How to add the graphs under selectbox?

I want to make a st.selectbox with the code below.
When I select Males vs Females, it shows that graph.
How can I put those code under selectbox?

st.write('Males vs Females')
gender_count = my_pop.groupby('Offences')['Males', 'Females'].sum()
gender_count.columns = ['Males','Females']
st.bar_chart(data = gender_count, use_container_width=True)

st.write('Adults vs Juveniles')
gender_count = my_pop.groupby('Offences')['Adults', 'Juveniles'].sum()
gender_count.columns = ['Adults','Juveniles']
st.bar_chart(data = gender_count, use_container_width=True)

You can use an if statement and st.selectbox to control the flow of your app.

option = st.selectbox("Select an option:", ["Males vs Females", "Adults vs Juvenils"])

if option == "Males vs Females":
    st.write('Males vs Females')
    ...

elif option == "Adults vs Juvenils":
    st.write('Adults vs Juveniles')
    ...

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