I have a page that contains many forms for data annotation purposes. In fact, for each data point, there are two forms: one imports a few attributes from another data point, and the other saves the data point to a sqlite3 database.
Here’s the problem:
If the annotator completes a few forms in a row, they can’t save all of them at once. They have to click save for each form.
Since I have the components’ keys in the session_state, I thought I could just get the data for each component and do the saving for all of them. Unfortunately, it seems Streamlit only passes the data to the session_state once the submit button is clicked. Is that a correct assumption?
Would there be a way to implement this functionality?
Hi @ogabrielluiz , maybe you can approach the solution without using forms: Just use the standard input widgets to gather data into your session variables and have 1 common submit button to send your data to the database. After database commit, you can reinitialise your widget variables.
That’s a good suggestion. Since each widget has its own state held under its key, there’s no need to create separate session state keys. Can you use a global callback which persists the current global state across all widgets? Does the annotator user need to restore saved states from one session to the next (annotation takes time and it would be frustrating to lose a session)?
The problem is that there are some selectboxes. When the interaction happens the data is lost.
Also, an import functionality gets data from another object and copies it to the current object. When this happens we also get a page reload which erases the data.
Another thing is the page reload: on every interaction, there will be a reload. So if the person has to choose 10 objects on a multiselect, there will be 10+ reloads by the end of the process.
The problem with having this is that on each interaction there’s a reload. So, basically the person won’t be able to finish a form without the page reloading many times.
You can use the state value of one control to initialize the value of another (provided the other is rendered after the first). The toggle state of a checkbox is preserved on a rerun (not so for buttons). Sometimes I find it’s more “reliable” to set the dependent values that need to be used in components further down in your code in the on_change / on_click callback of the earlier component in your code which supplies the value. (That is rather than direct assignment to a variable.)
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.