-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session State to Prepopulate Inputs #4831
Comments
Hi Ryan, thanks for flagging! I'm having trouble reproducing this locally. Here's a short video demonstrating how your code snippet behaves for me—is this different from what you're seeing? If so, can you please upgrade to the latest Streamlit release (1.10.0) and let me know if the behavior persists? Thanks! |
Hi Caroline, It appears upgrading may have fixed the issue with the text input, however I am still having issues with the multiselect. I've attached the slightly modified code and a GIF showing what's happening on my end. Thanks!
|
Hi @ryantaylor406, thanks for sharing that! The reason you're seeing this behavior is that when you change the value of the multiselect widget, the Streamlit app reruns (causing the value of the multiselect to revert to the value you had previously saved in session state). To avoid rerunning the app, you can use st.form to provide a submit button that users click after they've finished interacting with the multiselect widget. The app won't rerun until the user clicks that button. Here's an example (hosted here so you can try it out):
|
I see same problem in your example with form. Select one item first time - submit - all ok |
You may want to try this new library. Solve my similar problem...https://github.com/PaleNeutron/streamlit-ext |
Summary
I have a multipage app and I am trying to prepopulate the inputs on Page 1 with their previous input (if it exists) using st.session_state. The code I have written seemingly works at first (prepopulates the default value with their previous input) but when you go to change the value of the input, it seemingly deletes your entry and forces you to re-enter the value (works on the second attempt). I have tested this on text_input and multiselect but I imagine this happens with other inputs as well.
Steps to reproduce
Code snippet:
Expected behavior:
I expect to be able to change the value of the input without it getting erased and having to re-enter it a second time for it to stay.
Actual behavior:
First entry when trying to change the value is immediately erased, have to type input in a second time for it to stick.
Is this a regression?
Never attempted this before on previous versions.
Debug info
Additional information
I am open to trying different ways of prepopulating inputs if anyone has done something similar before.
The text was updated successfully, but these errors were encountered: