How to initialize the value of slider

I am currently developing an application that does image processing in streamlit.
I am using slider to manage the image processing parameters. I need to return the value of the slider when the user selects a new image.
Is there any way to achieve this in streamlit?

Hi @mrkm99, welcome to the Streamlit community!! :partying_face: :confetti_ball:

Would you mind re-wording your question? If you meant you wanted to use the current value of the slider widget, you can simply assign st.slider to a variable var. This variable var would contain the value of the slider.

To set a default value when the slider first renders, set the value parameter to the desired value in st.slider.

For example, I’ve created two sliders s1 and s2 that contain the current returned value of the sliders. Next, I add and multiply the returned values and display the result:

# slider-init.py
import streamlit as st

s1 = st.slider("slider 1", min_value=0, max_value=10, value=3)
s2 = st.slider("slider 2", min_value=1, max_value=10, value=1)

st.write(f's1 + s2 = {s1 + s2}')
st.write(f's1 * s2 = {s1 * s2}')

$ streamlit run slider-init.py

slider-init

If I misunderstood you, please feel free to correct me :grinning_face_with_smiling_eyes:

Happy Streamlit-ing! :balloon:
Snehan

2 Likes

Hello ,@snehankekre .
Thanks for the reply! Sorry,there was a mistake in the question.
" I need to initialize the value,position of the slider when the user selects a new image."
I apologize for my lack of English.
Please let me know how to solve this problem.

I was able to achieve initialization by updating the slider key to a new one at the time of resetting.
https://discuss.streamlit.io/t/reseting-the-app-via-a-button/705

import SessionState
import streamlit as st

def create_slider(state):
    if state.frag_slider_reset:
        state.reset_num += 1
    for name in ["a","b"]:
        state.params[name] = st.slider(name,0,100,0,1,key=str(state.reset_num))
    
    state.frag_slider_reset = False

state = SessionState.get(params=None,reset_num=0,frag_slider_reset=False)
state.params = {}

if st.button("reset"):
    state.frag_slider_reset = True

create_slider(state)
st.write(state.params,state.reset_num)

Hey,@snehankekre.
Does this method cause memory issues?