How to set single default value for select_slider?

Hi everyone!

I want to display a slider with the following options: [1000, 2000, 5000, 10000, 50000, 100000], and have 10000 as the initial default value. Here is the expected result:

Kapture 2023-11-25 at 11.31.07

Since the step varies, st.slider won’t work here, so I chose st.select_slider, which treats each option as a category:

iterations = st.select_slider(
        label="Iterations",
        options=[1000, 2000, 5000, 10000, 20000, 50000, 100000],
)

There is a value argument in the st.select_slider widget to set the default value. If none is provided, the initial default is the first element from the options list. This is not the behavior I want for my use case. However, I can’t set value=10000 either, because it only accepts iterables, in order to create a double-ended slider, which I also don’t want.

Is there a way to create a widget as shown in the GIF?

Seems to work for me (Streamlit 1.28.2).

1 Like

If you look at the options for value in st.select_slider - Streamlit Docs, you will see that it can be a single value or a tuple, so passing a single value from your options will work fine.

2 Likes

It works indeed. I feel dumb, I could’ve sworn that I tried value=10000 and it gave me an error, but clearly I was doing something else. Anyway, next time I’ll double check. Thanks @Goyo and @blackary for your help (and patience)!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.