Persistent States

How can one store a value across pages?

For example you have page A and page B

How would you store a value received from a widget such as a select box or number input?

Let’s pick a widget for example ‘Select box’

My attempts

Choices ABC or XYZ

  1. XYZ is selected (Page A) but when changing to Page B and then going back to (Page A) ABC is selected.

  2. XYZ is selected (Page A) when changing to Page B and back (Page A) it remembers the selection XYZ but when attempting to change back to ABC it changes it to ABC then XYZ again. You have to select ABC again then it will work but that’s selecting ABC twice! This also happens if you don’t change the page.

  3. Using the method in option 2. and setting a key for the widget works and no double selecting. However, we now get 'The widget with key “page_a” was created with a default value but also had its value set via the Session State API.

I have not found a way to persistently store session states correctly. Option 3. is the best but have to suppress warning messages and write boiler plate/pad the code when using widgets.

Using Streamlit, version 1.32.0

For example, if someone wants a settings page to select text colour they could select ‘green’ then each page they go to when something is printed is green.

Streamlit is handy for one page but comes unusable across multiple pages/files unless I am unaware or doing something wrong.

I’m giving up for now, can anyone suggest the correct way to persistently store session states correctly?


I have posted a basic example for selectbox to persist data across pages.