Any plan to support the value of sidebar.slider update?

Any plan to support the value of sidebar.slider update?

Hi @nvidia

This is actually to some extent already possible from Streamlit version 0.84.0 and forward by utilizing callback functions on widgets. See for instance this blogpost for a description and pointers to documentation and my example below setting a slider to random values. There is a bug for range sliders in the current version though.

import streamlit as st
import random

def _update_slider(value):
    st.session_state["test_slider"] = value

if "test_slider" not in st.session_state:
    st.session_state["test_slider"] = 0

st.sidebar.slider("My slider", key="test_slider", min_value=-100, max_value=100)

st.button("Update slider values", on_click=_update_slider, kwargs={"value": random.randint(-100, 100)})



It’s seems feasible, thank you very much, Peter

Hi there!

This example doesn’t seem to be working for me. Has something changed in the way widgets are handled?

If I actually look at the session_state output, I can see that the values are being updated as I click the button. However, the value (and hence its position) on the slider itself doesn’t change.

Hi @Dhruv_Sharma, welcome to the community! :wave:

Thanks for flagging! This is a known issue and is currently in the process of being fixed. You can track the progress here:

Best, :balloon:

1 Like