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