How to use a range slider session state?


Can’t use st.session_state values of a range slider.
Documentation does not mention this point.

Steps to reproduce

Code snippet:

values = st.slider(
    'Select a range of values',
    0.0, 100.0, (25.0, 75.0), key=myvalues)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

IMHO, for consistency with other widgets, both st.write should return the same output.

Actual behavior:

st.session_state returns some kind of collection (<class ‘method’>) when working with range sliders. The documentation is not clear about this and does not mention how convert to a tuple or list.

Debug info

  • Streamlit, version 1.14.1
  • Python 3.10.8
  • Not Using Conda! No PipEnv! No PyEnv! No Pex!
  • OS version: Win 11
  • Browser version: Chorme v107.0.5304.107

If you’re using a variable myvalues for the value of the key, you should use dictionary-style access for st.session_state, so that you’re actually looking at the same value. This works fine:

import streamlit as st

key = "myvalues"

values = st.slider("Select a range of values", 0.0, 100.0, (25.0, 75.0), key=key)
st.write(st.session_state[key]) # note that if I do `st.session_state.key` it won't work, because the key is not `key` it is `"myvalues"`