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

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?

Thanks

Hi @tbrown, did this get resolved? If yes would love to know how you resolved itā€¦