In my code once the user chooses the state from the first dropdown, I want to display counties only from that state in the second dropdown. Currently it always filters the county to Alaska which is the first state listed in the state dropdown.
import streamlit as st
import pandas as pd
st.sidebar.info('### ***US States and Counties***')
with st.sidebar:
# Add a dropdown to select a state
state_county_data = pd.read_csv("https://raw.githubusercontent.com/kjhealy/us-county/master/data/census/fips-by-state.csv",encoding = 'unicode_escape')
states = sorted(state_county_data["state"].unique())
selected_state = st.selectbox("Select a state", states)
# Use the state code to filter the counties dataframe
counties = sorted(state_county_data.loc[state_county_data["state"] == selected_state]["name"].unique())
# Add a dropdown to select a county
selected_county = st.selectbox("Select a county", counties)
# Show the selected state and county
button = st.button('Update')