Streamlit slider DuplicateWidgetID key error

Hi all,

I’ve been trying to get a slider working

budget = st.slider('Select Budget', min_value=1000, max_value=8000, step=5000, key='2') 
df = df[df['price'] <= budget] 

But I kept getting this error (I don’t have any other slider)

DuplicateWidgetID : There are multiple identical st.slider widgets with key='2' .

To fix this, please make sure that the key argument is unique for each st.slider you create.

Does that mean for each step that I shall create a separate key? Any hints are appreciated. Thank you!

Hi @meitw, welcome to the Streamlit community!

Can you post a larger code snippet? That piece of code doesn’t suggest much in terms of what the error might be.

Hello @meitw,

Like randy said, a more complete code snippet may help us better to understand the issue.

From what you’ve posted, I suppose this slider is inside some for or while loop.
If that’s the case, make sure to have different keys for each iteration.

1 Like

@randyzwitch @okld
Thank you for the reply! Indeed I put the
budget = st.slider(‘Select Budget’, min_value=1000, max_value=8000, step=5000, key=‘2’)
df = df[df[‘price’] <= budget]
Under a for loop for the select box with the wrong indentation.
Now it’s all good. Thanks!

2 Likes