Reseting the app via a button

Is there a method by which I can reset the app through the click of a button?

2 Likes

Hey @rohanvartak1996! Welcome to our forums :wave:

If I understand you correctly, you’ll need to use a feature we’re still designing, called “Session State”. You can find more about it here.

In the meantime, we have a prototype implementation you can download from this Github Gist.

After you download that, you can reset widgets by using the SessionState object along with custom widgets keys:

import streamlit as st
import SessionState  # Assuming SessionState.py lives on this folder

session = SessionState.get(run_id=0)

if st.button("Reset"):
  session.run_id += 1

st.slider("Slide me!", 0, 100, key=session.run_id)

And if you want to put the reset button at the bottom, you can use an st.empty() placeholder:

import streamlit as st
import SessionState  # Assuming SessionState.py lives on this folder

session = SessionState.get(run_id=0)

slider_element = st.empty()

if st.button("Reset"):
  session.run_id += 1

slider_element.slider("Slide me!", 0, 100, key=session.run_id)
3 Likes

Is the solution scalable? Like how many keys we can have in streamlit,with reset button press the number of keys increases and decreases app performance I feel