Preserve widget state when a widget disappears from the page (demoed via Multipage Apps)
See original GitHub issueChecklist
- I have searched the existing issues for similar issues.
- I added a very descriptive title to this issue.
- I have provided sufficient information below to help reproduce this issue.
Summary
When you set a session state variable via the
st.some_input_widget(..., key="foo")
The value of session_state.foo is overridden when you leave that page and go back to that page.
I created an example of this which you can see here
Reproducible Code Example
# See the live example on Streamlit Community Cloud
Steps To Reproduce
- Go to the live app.
- Type in “ABC” in the text box which should bind it to the state variable “foo”
- Optionally, click the button to set the “bar” state (this is included only to show that other forms of state are properly preserved across state views).
- Click on the second page.
- Click back to the main page.
Expected Behavior
When you complete step (5) the text you entered (“ABC”) should still be be bound to “foo” and appear on that page.
Current Behavior
“foo” has been overridden when you go back to the main page.
Is this a regression?
- Yes, this used to work in a previous version.
Debug info
- Streamlit version:
1.15.2
- Python version:
3.10.6
- Operating System:
MacOS 12.6.1 (21G217)
- Browser:
Chrome Version 107.0.5304.121 (Official Build) (arm64)
- Virtual environment: Python venv
Additional Information
No response
Are you willing to submit a PR?
- Yes, I am willing to submit a PR!
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Multi-page apps with widget state preservation. The simple way
Hi all, Here are some skeleton code snippets to show the possible use of multi-page apps, with preservation of the widget states.
Read more >Preserve widget state when temporarily removed from tree in ...
The reason why the widget loose its state when removed from the tree temporarily is, as Joshua stated, because it loose its Element/State....
Read more >Multi-Page Apps and URL Support - Dash Plotly
This is an OrderedDict that we can extract information from about our app's pages. In our app.py we loop through all of our...
Read more >Get Started with Flutter Authentication - Auth0
This widget defines a view that your app shows to users who have not been authenticated yet by Auth0. It displays a login...
Read more >Simple app state management - Flutter documentation
On this page, we are going to be using the provider package. ... In Flutter, it makes sense to keep the state above...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also made a note for myself to dig deeper into this once I have some free time. Lots going on right now!
Hi @kmcgrady, thanks a lot for taking this into consideration.
I think that for common use cases, the persistent state as default makes more sense. For example in a multi-step form entry for a CRUD app, or in a complex computation with multiple parameters grouped in tabs/pages, you normally would not want the application state to be reset just because the entry widget is hidden.