Session state key-widget association bug

Hi guys,

Think I’ve found a bug unless I’ve misunderstood something. The bug comes when trying to reflect session_state value into a slider, but only when the slider has two values.

Example that works as intended:

import streamlit as st

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

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

Example with bug:

import streamlit as st

if "test_slider" not in st.session_state:
    st.session_state["test_slider"] = [50,100]

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

Error:

Am I misunderstanding something in the intended usage or is this a bug?

EDIT: Tried it on 0.85.1 and 0.86.0.

1 Like

Hey @PeterT,

You may have found a subtle bug here. I’m sending this on to the team to check it out! :space_invader:

Thanks so much for such a clear and concise question with an MWE of how to reproduce it!

Happy Streamlit-ing!
Marisa

1 Like

Hi @PeterT : This is a known bug: Allow initialization of range slider with session state · Issue #3586 · streamlit/streamlit · GitHub

This is on the engineering team’s radar. We don’t have a solution or workaround yet, but we’ll keep you posted with updates on our end.

Thanks,
Abhi

2 Likes

Ah thanks @abhi - I missed that issue in my search :slight_smile: Thanks - looking forward to it.

1 Like