question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Caching reverts widgets to initial state

See original GitHub issue

Summary

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:

  1. Start with a new streamlit run! The problem usually goes away after the first try
  2. Click the “select” checkbox
  3. 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MartinNowakcommented, Oct 21, 2020

Indeed seems to fixed in newer versions.

1reaction
akrolsmircommented, Oct 2, 2020

Can also confirm this repros! Thanks for the detailed repro case with explanations of which lines are necessary =)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found