-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Checklist
- I have searched the existing issues for similar feature requests.
- I added a descriptive title and summary to this issue.
Summary
If you change any parameter of a widget in Streamlit (e.g. the label or the default value), Streamlit will treat it as a new widget and reset its state. That’s necessary because we determine which widget state belongs to which widget based on the parameters. (Note that there are a few exceptions to this rule, e.g. changing the disabled parameter will not reset the widget).
But we still do this when you manually set key! Even though in that case, we can easily associate the widget state with the widget based on the key. We should change that and always preserve the widget identity if key is set.
Why?
This (potentially) fixes lots of small issues such as:
- Erratic behavior in selectbox when the index parameter is not a constant #1532
- Selection flips back to previous selection on click #4854
- Selectbox resets selection on visible name change #6352
- st.chat_input drops submission after placeholder text change #7054
- Using st.data_editor with session state, input data "disappears": Requires double input to register changes. #7749
st.multiselectreturns empty on dynamically changing options. #7855- st.date_input value is not changing while using session_state #8410
st.selectboxsometimes ignores user input when order ofoptionschanges #8496- Unable to persist camera view in 3d plotly charts #8882
- Allow dynamic label on button with fixed key #9402
- Exponential slowdown in Streamlit as the number of widgets increases (starting in v1.34) #9415
- After first input, st.number_input requires to input twice to get the right value returned if the widget's value parameter is assigned a class property which is stored in st.session_state #9657
st.data_editordoes not persist scroll position (x,y) after on_change refresh, when dependent/virtual columns are also updated #10181- The button type parameter causes the button function to be invalid #10843
- selectbox selection is discarded when format_func output changes #11268
- State not working as expected, at least for checkboxes #12165
- Flickering Dataframe when using st.fragment, but only when
on_selectis provided #9527 - Fixing state management issues with Streamlit's st.pills component where selections get reset when available options change dynamically and pills require double-clicks to toggle #12392
- With zoom events on charts/maps, this could unblock use cases where you dynamically want to load data while zooming in.
How?
We need to be careful here since this might break apps. Probably needs a bit of investigation.
Additional Context
No response