A dashboard filter often needs more than one answer: a user might want several product categories or states at once. A multiselect is a drop-down control for choosing any combination of options. In Streamlit, `st.multiselect('Color', ['blue', 'green', 'red'])` displays a labeled control that accepts one or more colors. Its required arguments are a label and a list of options. section 6.3.1
For a data-driven filter panel, populate each control from the distinct values in its dataframe column. `list(df[column].unique())` produces that option list. Put the controls in an expander and use `st.columns` to arrange them side by side; save each control’s returned selections under its column name. section 6.3.1
def filter_panel(df):
filters = {}
with st.expander("Filters"):
filter_cols = st.columns(len(filter_dims))
for idx, dim in enumerate(filter_dims):
with filter_cols[idx]:
unique_vals = get_unique_values(df, dim)
filters[dim] = st.multiselect(dim, unique_vals)
return filters
The filter-panel function shows how to collect selections from several multiselect controls into one dictionary. section 6.3.1
Displaying controls alone does not filter the data. Pass the returned dictionary to a filtering function: for each column with selected values, keep rows whose value is in that selection. Skip columns with no selections. The resulting dataframe can then drive the displayed dashboard data. section 6.3.1
Choose a drilldown breakdown
A drilldown can use a single `st.multiselect('Drilldown fields', [...])` to let users choose which dimensions appear in an aggregated metrics table. When dimensions are selected, group the dataframe by those fields; when none are selected, calculate metrics for the entire dataframe instead. This makes an empty selection a useful overall view rather than a dead end. section 7.5.2 section 7.5.3
