Use st.expander to place optional content in a collapsible panel. In a dashboard, hiding filters keeps attention on the displayed data while allowing users to reveal controls when needed. section 6.3.1
Collapsible filter panel
Wrap the filter controls in with st.expander("Filters"): create layout columns inside the panel, populate multiselect widgets, and let users expand or collapse the complete filter area. section 6.3.1
Listing 6.4 A starting draft of filter_panel.py
import streamlit as st
from data_wrangling import get_unique_values
filter_dims = ["age_group", "gender", "category", "segment",
"product_name", "state"]
def filter_panel(df):
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)
st.multiselect(dim, unique_vals)
Inspect the complete starting filter_panel implementation, including the expander, column layout, unique values, and multiselect controls. section 6.3.1
