question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preserve widget state when a widget disappears from the page (demoed via Multipage Apps)

See original GitHub issue

Checklist

  • 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

  1. Go to the live app.
  2. Type in “ABC” in the text box which should bind it to the state variable “foo”
  3. 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).
  4. Click on the second page.
  5. 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:open
  • Created 10 months ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
jriekecommented, Dec 7, 2022

Also made a note for myself to dig deeper into this once I have some free time. Lots going on right now!

0reactions
matkozakcommented, Dec 9, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found