I created a rough draft video showing an introduction to session state. I plan to re-record it with better audio and editing, but I wanted to get community feedback before I invested in a more polished presentation.
The video is aimed toward users who have either read through documentation already, or walked through their first app creation in another basic tutorial. Many questions in the Using Streamlit forum seem to boil down to details about session state, so these are the details I was figuring out in that first week or two of playing around with Streamlit.
(Video is processed up to 720p at time of posting. Higher resolution expected within a couple hours. )
Any thoughts feedback before I record the final version?
Super clear to me. Iām sure itāll be very useful. (Not sure the assignment of ss.c2 will work on the first run as the key c2 will not have been createdā¦ best check that.)
I know when Iām messing around with session_state (especially when making live edits) I can get the warning about a widget getting created. Iām trying to recreate it to get the exact message, but now that Iām trying itās not breaking for me. Iām not having a problem just creating a key before the widget and having it initialize with that value, though.
In fact, Streamlit must have some āshadow memoryā besides whatās explicitly available by key. Iām getting a checkbox to remember its state even if I forcibly delete its key before rendering it (though it forgets if I build in extra interactions/page refreshes while its not rendered).
Looks like I have something to experiment with to put into a part 2.
In my opinion describing the ābest practiceā approach rather than the nuances of edge cases will help 90% of your audience. Though I personally like the details, theyāre not useful for most.
If youāre interested, I wrote a gist explaining some aspects of this topic here. I like your explanation better.
Hi @mathcatsand, just started going through your video. Informative, with examples - should help viewers realize how state values change during a refresh cycle.
I have a teeny suggestion though: however aesthetically possible, group your widgets into columns, so that the font in the right pane can be consequently increased. It will help those who view your video on mobile devices.
The other suggestions (audio, etc.) Are already part of your to-do list.
Thanks @mathcatsand (and @asehmi for your gist referenced above). Both helped a lot with a session state issue that Iām grappling with. I found the video very practical and a great introduction to the dynamics of session state (beyond the absolute basics). It would have saved me a lot of time when I started using session state. Regarding feedback before you record a final version: I think this version works perfectly well as a final version!
Thank you, thank you very much @mathcatsand for this guide. One question if I may: Is the ā_holdā structure you used the standard approach in multi-page apps to keep the widget values once you revisit a page? Thanks again!!
I donāt know if itās any kind of standard, itās just what I figured was logical since keys go away along with their widgets.
Iāve seen two approaches taken:
As I did in the video, make a secondary set of keys not tied directly to any widget so they persist for the entire session without worry of any particular widget being rendered or not.
Create a copy-paste function at the top of every page to ākeep them alive.ā For a list key_keeper of widget keys you want to protect from deletion, put at the top of each page:
for key in key_keeper:
st.session_state[key] = st.session_state[key]
Iāve seen the latter frequently around the forum, but my personal style leans toward the former.
It would be nice if widgets had optional arguments to protect their keys from deletion within Streamlit. I get that deleting widget keys by default is good for cleanup, but this seems like a frequent enough use-case that itād be a good feature. (I havenāt looked on GitHub to see if its posted as a feature request already. I should lookā¦)
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.