I am trying to create multiple sliders through FOR loop for storing user inputs. These sliders first render with some fixed values and the user can change these sliders to new values.
I want to give “Reset” st.button option to users where this resets sliders to its original state.
I tried deleting session_state with the Reset button. however, this does not reset the rendered slider on UI.
Here is the code:
import streamlit as st
slider =
s_min = 0
s_max = 10
default_cal = 5
if st.button(‘Reset’):
for key in st.session_state.keys():
del st.session_state[key]
slider =
f = 0
for key in st.session_state.keys():
st.write(‘keys are’)
st.write(st.session_state[key])
for i in range(3):
var_number = i
slider.append(st.slider(‘Change variable value:’, s_min, s_max, default_cal,
key=“sld_%d” % var_number ))
import streamlit as st
slider =
s_min = 0
s_max = 10
default_cal = 5
number_of_sliders = 5
if st.button(‘Reset’):
for key in st.session_state.keys():
del st.session_state[key]
slider =
f = 0
for key in st.session_state.keys():
…st.write(‘keys are’+key))
…st.write(st.session_state[key])
for i in range(number_of_sliders):
…var_number = I
…slider.append(st.slider(‘Change variable value:’, s_min, s_max, default_cal,
…key=“sld_%d” % var_number ))
“I tried deleting session_state with the Reset button. however, this does not reset the rendered slider on UI.”
This is exactly my issue as well. I can reset the variable that the widget controls, but the widget visible on the UI is not reset. Therefore, after reset, if I change any widget, any other widget that was changed before the reset is the same as before the reset.
@Costantino_Terranova, tried to follow your guidance, and it mostly worked for me, but after resetting the slider it only registers my adjustment after I interreact with it twice, seems like its re-rendering the slider after my input. appreciate any advice you can offer! see gif below…
Has there been any update to the reset filters for the st.slider? The suggestion by @Constantino_Terranova only responded after clicking the button twice
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.