New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent session state behavior when used with widgets #4338
Comments
Hmmmm 🤔 interesting Just passing by and did not read much into it yet, but do you think it's consistent with https://docs.streamlit.io/library/advanced-features/widget-semantics#advanced-notes-on-widget-behavior point 5?
So the session state for a disappearing widget would be dropped? |
As I understand point 5, the widget state should be dropped if there is no related session state item. The following statement in the documentation seems to confirm this:
I assume that's what I'm doing here: if "widget_unbound" not in st.session_state:
st.session_state.widget_unbound = "hello" Nonetheless, my session state is either dropped and recreated every other script run (first case), or reset to its initial value (second case). This behavior is related to a new widget semantic adopted in version 0.89.0 #3827. |
I first encountered this behavior with my multi-page sample code here. To preserve session state values once the widgets disappear (when going from Settings to Home page), I had to re-apply session state values on themselves. |
Leavin this here for others but as @AnOctopus says, |
Thanks for the answer, I'm closing the issue for now. |
Just want to add that I added this discussion to our roadmap for future session state improvements. I think if it really currently works as you pointed out above, this is indeed pretty confusing and something we should change at some point... |
Chiming in to say I'm having the same issue, it makes it pretty cumbersome to write multi-page apps where different processing and visualizations might appear on different pages based on widget values. |
Hey @scott-trinkle, maybe you could try the following solution: https://gist.github.com/okld/0aba4869ba6fdc8d49132e6974e2e662
|
Summary
Session state in Streamlit 0.89.0 to 1.5.0 has a strange behavior when bound to widgets (
key
parameter).Steps to reproduce
First case
R
. ISSUE: Session state item doesn't exist anymore.Second case
ISSUE: Widget does not take value from session state.
R
. ISSUE: Session state item resets to its initial value.Code snippet
Feel free to compare the following script behavior with Streamlit 0.88.0 (working session state) and Streamlit 1.5.0. Both cases are implemented.
Is this a regression?
Yes, session state with widgets worked as expected from version 0.86.0 to 0.88.0.
Debug info
The text was updated successfully, but these errors were encountered: