Hello everyone, I’ve been developing a feature that enables users to save the current state of the app as a project. When starting a new session, the app will automatically refresh with the previous state. This process involves configuring session state keys before initializing the corresponding widgets. As a result, a message related to a field on the UI is displayed.
The widget with key “ref_well_lat_range” was created with a default value but also had its value set via the Session State API.
Any suggestions on how to do this properly or how to hide this message from UI.
Every widget with a key is automatically added to session state, and if you create a widget with both a key and a default value, that default value will be added to session state (
st.session_state.ref_well_lat_range in this case). If you are providing both a key and a default value for the widget, you’ll see this error message if you try to then modify the session state value for that key via
st.session_state.ref_well_late_range = some_new_value.
To avoid this error, you can either:
- remove the default value for the widget with key
- remove the line where you’re modifying the widget’s session state value (i.e.
st.session_state.ref_well_late_range = some_new_value)
Hope this helps! This section of the docs covers this concept in more detail.