so when i choose arizona, for states, the cities will only have one value, phoenix, but if i add california, the citie will consist of three value phoenix, sacramento, los angeles…
so I can filter based on just states or with specific cities
If you only want it one way (state affects cities), that’s pretty straightforward. I’ll assume cities and states are in a single data frame to simplify the code and express the Streamlit part specifically.
import pandas as pd
df = pd.DataFrame({'city':['phoenix','sacremento','los angeles','austin','houston'],
'state':['arizona','california','california','texas','texas']})
states = st.multiselect('States', df['state'].unique())
if states != []:
cities = st.multiselect('Cities', df[df['state'].isin(states) ]['city'].unique())
If you want some bidirectional effect between widgets, that gets a little more complicated and requires session state and callbacks.