Caching reverts widgets to initial state
See original GitHub issueSummary
After an interactive widget is used, the value of the user input is reverted back to the default value the next time the page updates (when the script is re-run).
Steps to reproduce
What are the steps we should take to reproduce the bug:
- Start with a new streamlit run! The problem usually goes away after the first try
- Click the “select” checkbox
- Click the “test” checkbox at the bottom of the page
import seaborn as sns
import streamlit as st
@st.cache(suppress_st_warning=True) # caching is required
def updt_data():
st.balloons() # streamlit function is required
return None
updt_data()
select = st.checkbox("Select")
# any type of plot widget or specific seaborn functions such as get_dataset_names() or
# load_dataset() is required here
sns.get_dataset_names()
st.write("Selected?", select)
st.checkbox("Test")
Expected behavior:
The value of ‘Select’ remains True because the “select” checkbox is checked.
Actual behavior:
The value of ‘Select’ changes to False even though the “select” checkbox is checked.
Is this a regression?
No
Debug info
- Streamlit version: 0.66
- Python version: 3.8
- PipEnv version: 20.2
- OS version: MacOS Catalina
- Browser version: Chrome 85
Additional information
May be related to one of the following issues: https://github.com/streamlit/streamlit/issues/1532 https://github.com/streamlit/streamlit/issues/1259
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Caching child widgets vs. recreating them - flutter
I therefore conclude that whenever a Widget changes State, subtrees that do not change based on the state should be cached and reused....
Read more >Riverpod Data Caching and Providers Lifecycle: Full Guide
The provider's state is initialized when the first listener is registered; Every time the state changes, all listeners will be notified so they ......
Read more >Session State Variables are re-initialized to initial state going ...
The widget is being created anew on each page so its value is being initialized to its default value. I'd create a separate...
Read more >Streamlit Tricks — Application Reruns on Every Widget Click ...
The other workaround, is the combination of button widget along with SessionState, st.session_state .In order to control the state of the button ...
Read more >Preserving Application State (Web Development)
For example, an application accepts a user name on the first HTML form. ... that are cached can be used to save the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Indeed seems to fixed in newer versions.
Can also confirm this repros! Thanks for the detailed repro case with explanations of which lines are necessary =)