I have two users that wanna have different views of data so I’d like to add a toggle that will toggle between the two differing views (it’s a very minor difference). But I would like streamlit to remember what the user’s toggle selection is so next time they come to app they don’t need to toggle it every time.
Is there a way for streamlit to remember or cache this instead of resetting to a default selection when they leave the app?
For example, if I have this radio widget:
selection = st.sidebar.radio(
“What’s your favorite movie genre”,
(‘Comedy’, ‘Drama’, ‘Documentary’))
If a user selects the Drama option, use the app and leaves the page. I want the Drama option to be selected upon their return.
If you have somehow a user management system in the app, you can save their last values to a dictionary and call it from the dict when they come back. However, you have to know who is using so maybe you can create a small text box to enter the username before starting the calculations.
You can modify the “value” attributes based on the dict and inputted username.
Of course, it will be very insecure since everybody can write anything, but it depends on your requirements.
Sorry I forgot to specify that i had setup SSO through NGINX on my app so my users have to authenticate to access the app. So my idea was to pull their username from this (not sure how) and to use that to set the value of the toggle as you say.
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.