"StreamlitAPIException: Values for st.data_editor cannot be set using st.session_state" using data_editor to delete rows

I think I might have determined the cause of this exception. I had code that was initializing the state for all my keys, and then I used those keys in the code that followed. It followed this pattern:

initialize_state()

st.file_uploader(
   "Choose an input spreadsheet (.xlsx)",
   type="xlsx",
   key=<Key I initialized in the above function>,
)

The Streamlit code that throws the error is lib.streamlit.elements.utils.check_session_state_rules in the event the passed in write_allowed parameter is False. You can easily find the code by searching for the variable SESSION_STATE_WRITES_NOT_ALLOWED_ERROR_TEXT. For widgets like forms, file uploaders, etc, the check_session_state_rules is called with the write_allowed parameter set to False.

1 Like