liveBook · Manning

Dropdown

As explained in The Well-Grounded Data Analyst

A Streamlit input widget that displays selectable options in a dropdown control.

A drop-down menu is a Streamlit input widget for choosing one option from a list. In an interactive proof of concept, the selection filters data and updates the displayed analysis. section 11.2.2

Use drop-down menus to:

  • Offer fixed choices, such as counties loaded from property data. section 11.2.2
  • Create dependent choices, where available towns depend on the selected county and streets depend on both county and town. section 11.2.1 section 11.2.2
  • Represent an unselected state with placeholders such as “-- No town selected --”. section 11.2.2
  • Apply the selected values to a pandas query before calculating metrics, charts, and raw results. section 11.2.2

House price explorer

Three Streamlit selectboxes let users choose a Welsh county, town, and street. The app then reports record counts and median sale prices, displays charts, and shows the filtered raw data. section 11.2.2

st.header("Explore house prices at different levels")

select_col1, select_col2, select_col3 = st.columns(3)

with select_col1:
    county_select = st.selectbox(
        'Select a county:',
        helpers.get_counties(wales),
        index=None,
        placeholder="-- Select a county --"
    )

TOWN_NULL_VALUE = "-- No town selected --"    #1

with select_col2:
    town_select = st.selectbox(
        'Select a town:',
        helpers.get_towns(
            wales,
            county_select,     #2
            null_value=TOWN_NULL_VALUE),
        index=None,
        placeholder=TOWN_NULL_VALUE
    )

STREET_NULL_VALUE = "-- No street selected --"

with select_col3:
    street_select = st.selectbox(
        'Select a street:',
        helpers.get_streets(
            wales,
            county_select,
            town_select,
            null_value=STREET_NULL_VALUE),
        index=None,
        placeholder=STREET_NULL_VALUE
    )

Inspect the selectbox implementation for geographic filtering, including columns, placeholders, and helper functions that populate dependent options. section 11.2.2

How The Well-Grounded Data Analyst covers it

How deep it goes
Explains selectbox layout, placeholders, dependent options, filtering, and downstream metrics, while deferring broader Streamlit features.
Examples
Uses county, town, and street selectors in a Welsh house-price explorer, alongside metrics, charts, and filtered raw data.
What it assumes
Assumes Python, pandas data, and helper functions while focusing Streamlit learning on displaying text, dropdowns, charts, and tables.
What you can do after
Build interactive Streamlit filters that drive pandas queries and update summary metrics, visualizations, and tables.
How it connects
Connects drop-down menus with Streamlit, pandas data filtering, caching, charts, tables, and proof-of-concept development.

Also explained in

Compare how 10 books explain dropdown →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Data Analyst. The section links point to the parts of the book it draws on.