I have tried every example I can find on the forums for preserving session state and all of them throw errors related to something the session class doesn’t contain. Is there a working example anywhere that will allow me to save session state using any method for streamlit version 0.63.1? Is the solution that this version or streamlit doesnt work yet and I need to use an older version? If so which version will allow me to save session state using any method that works?
My use case is to have a checkbox in the sidebar.
Check the box in the sidebar and have a new checkbox appear in the page.
Click that new checkbox without have the whole page go blank or throw an error
I appreciate the help and hello everyone! Im new here and excited to see what this light weight web dev method can do!
I’m assuming you meant button instead of checkbox, since you don’t need SessionState for checkboxes because they preserve their return values on script rerun :
import streamlit as st
if st.checkbox('Click me'):
if st.checkbox("Click me too !"):
st.write("Hello world")
Whereas buttons don’t, so when you click the first one it gets to True but when you click the second one, the first one goes back to None and doesn’t pass the first check. So for this case :
First copy the SessionState gist in a SessionState.py file next to your app.py script.
Initialize a state to False. When you click the first button pass it to True and use it to bypass the check of the first button next time.
import SessionState
import streamlit as st
session_state = SessionState.get(checkboxed=False)
if st.button('Click me') or session_state.checkboxed:
session_state.checkboxed = True
if st.button("Click me too !"):
st.write("Hello world")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.