Just getting into Streamlit and have successfully been using session.state to save the state of some sliders on a Streamlit page.
Worked well in 0.88. Upgraded to 1.0 today and session.state appears to have stopped working.
Can’t find any info on this in the docs. - does it need some sort of cache clear?
I’m sorry to hear you’re having trouble using the Session State API. It would help if you could provide a reproducible code example demonstrating this behavior.
With Streamlit 1.0, I’m able to save the state of a slider widget as a Session State variable. Every widget with a key is automatically added to Session State. To learn more, check out Session State and Widget State association
The important thing here is that I need to keep my slider values if I navigate to another streamlit page and back again.
As stated, my code has not changed - I simply updated to v 1.0 from 0.88. so that iis why I ask if the API has changed.
I tried your example as written, but it seems that the key is not automatically added, so I get an error
stating this. it only works if I do this:
import streamlit as st
if 'myslider' not in st.session_state:
st.session_state.myslider = 0
slider = st.slider("my_slider",0,100,key="mySlider")
st.write('st.session_state["myslider"]=',st.session_state["myslider"])
my original code below, worked perfectly in 0.88 , the keys are saved and my sliders are remembered if I go to another streamline page and come back again.
import streamlit as st
if 'gen_level' not in st.session_state:
st.session_state.gen_level = 0
if 'gen_freq' not in st.session_state:
st.session_state.gen_freq = 5
if "gen_balance" not in st.session_state:
st.session_state.gen_balance = 0.0
st.slider('Level', min_value=0, max_value=10, key = 'gen_level')
st.write(" ")
st.slider('freq', min_value=0, max_value=10, key = 'gen_freq')
st.write(" ")
st.slider("balance", min_value=-10.0, max_value=10.0, key="gen_balance")
st.write(st.session_state.gen_balance)```
Thanks.
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.