I was thinking about state management when using custom components. I have uploaded a gist with a sample app that uses ace editor to edit, validate and download an yaml file.
The problem is that when the component key is not fixed, the compoenent reloads between page refreshs causing a bad user experience Video. With fixed keys this doesn’t happen.
This issue is not related only to ace editor, I noticed the same happen with streamlit-aggrid or any custom component that holds state.
In my projects I’m fixing the keys using a random value stored in session_state and changing this value whenever I need the compoenent to reset. One use case is when I want to clear the file uploaded in file_upload component after processing.
Have anyone faced the same situation? Any other ideas on how to manage that?
I encountered the same problem and gave it up.
My streamlit-webrtc component defines its key argument as a required, non-optional argument.
I think it’s unavoidable with the current Streamlit mechanism which tracks the identity of each component instance by checking its arguments unless key is provided. In such cases, when the input changes, Streamlit considers the component identity has changed and re-renders the component.
I do something similar too, but worry that caching of these random session state keys can get out of control. In effect, this would constitute a memory leak. Am I worrying for nothing?
these session state keys are not special, but just same as usual session state usage, so covered by Streamlit’s built-in session state management mechanism.
session state is bound to each session (ReportSession) and cleared when the session ends.
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.