Streamlit slider with variable number of arguments

I would like to customise the st.slider length based on the number of URLs a user inputs, using the slider so users can view the output for each inputted URL one at a time. I was hoping to use this code to create the variable length slider:

choices = []
for i in range(len(image_urls_list)):
    choices.append(i)
choice = st.slider('View results for image:', choices)

However, I get this error:

StreamlitAPIException: Slider value should either be an int/float or a list/tuple of int/float

It would be great if the slider can be used as an organisational feature!

Thanks,

Darcey

2 Likes

I’m still trying to understand what is it that you want to show with the slider. Can you explain it better?
Regardless, the reason for your error, is because choices is a list of integers. If you want to pass the number of items in choices, a simple len(choices) would do the trick. Just like passing len(image_urls_lists), but that’s probably because I haven’t fully understood the purpose.

seems your list contains others than interger or float, if not you can set your slider by an other way :

min_val = 0
max_val = len(max_value)

st.slider(β€˜x’,
min_value=min_val ,
max_value=max_val ,
step=1)