How do I create a list of values with st.slider in a loop?

Iโ€™m trying to use st.slider to allow a user to input new values to a list and then append that list of values to a dataframe called model_cities. Right now itโ€™s only saving the last value.

for x in (model_cities):
model_count =
x = st.slider(x, max_value=500, value=0)
model_count.append(x)

Not sure what Iโ€™m doing wrong. Is there an easier way to accomplish this?

This worked for me.

import streamlit as st
model_cities = [โ€˜Aโ€™, โ€˜Bโ€™]
model_count =
for i, x in enumerate(model_cities):
model_count.append(st.slider(x, max_value=500, value=0, key=โ€œcity_%dโ€ % i))
st.write(model_count)

Output:
{
โ€œAโ€: 149, # Slider controlled
โ€œBโ€: 260 # Slider controlled
}

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