Caching a User Selection

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 =
“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.

1 Like

How will you know who is using?

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.

1 Like

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.

That sounds good. All you need to create a database to save the last values and I can’t see a reason why it shouldn’t work.

But how do I read or get the username that the used to SSO into the app?