Summary
Hi all,
I’m attempting to get a multiselect box to pop up inside a form after making a selection with a radio button.
Steps to reproduce
Code snippet:
import streamlit as st
import pandas as pd
if "df" not in st.session_state:
data = {
"year": [2023, 2023, 2023, 2022, 2022, 2022, 2022, 2022, 2022],
"segment": ["a", "b", "c", "a", "b", "c", "d", "e", "f"],
"color": [
"red",
"black",
"white",
"blue",
"blue",
"red",
"red",
"green",
"yellow",
],
}
st.session_state.df = pd.DataFrame(data)
df = st.session_state.df
# User parameter selection
with st.form("my_form"):
col1, col2, col3 = st.columns(3)
min_results = 1
max_results = 20
select_results = col1.number_input(
"Select Number of Results",
min_results,
max_results,
value=20,
help=f"Select number between {min_results} and {max_results}",
)
select_sales_volume = col2.number_input("Select Minimum Sales Volume", 1, step=1)
select_opt_metric = col3.selectbox("Select Optimization Metric", ["A", "B", "C"])
col4, col5, col6 = st.columns(3)
select_years = col4.radio("Select Model Years", ("All", "Subset"))
select_segments = col5.radio("Select Segments", ("All", "Subset"))
select_colors = col6.radio("Select Colors", ("All", "Subset"))
col7, col8, col9 = st.columns(3)
if select_years == "Subset":
selected_years = col7.multiselect(
"Select Model Years",
sorted(df.year.unique()),
default=sorted(df.year.unique())[0],
)
if not selected_years:
st.warning("Select at least one model year", icon="⚠️")
if select_segments == "Subset":
selected_segments = col8.multiselect(
"Select Segments",
sorted(df["segment"].unique()),
default=sorted(df["segment"].unique())[0],
)
if not selected_segments:
st.warning("Select at least one segment", icon="⚠️")
if select_colors == "Subset":
selected_colors = col9.multiselect(
"Select Colors",
sorted(df.color.unique()),
default=sorted(df.color.unique())[0],
)
if not selected_colors:
st.warning("Select at least one color", icon="⚠️")
submitted = st.form_submit_button("Submit")
submitted
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
When selecting Subset in the radio button, a multiselect box should appear.
Actual behavior:
When selecting Subset in the radio button, the multiselect box does not appear.
Debug info
- Streamlit version 1.18.1