liveBook · Manning

Date selector

As explained in Build Python Web Apps with Streamlit

A date range selector is a user-interface control for choosing a start date and end date that define a period of interest.

A date range selector lets dashboard users choose a start date and end date, then inspect metrics and charts for that period instead of the entire dataset. section 6.1.3 section 6.3

A practical implementation follows this flow:

  • Display separate start-date and end-date inputs, usually in a sidebar. section 6.3.2
  • Choose defaults such as thirty days ago through the latest date available in the dataset. section 6.3.2
  • Convert the selected dates for comparison with the prepared data, then retain rows between the two endpoints. section 6.3.2
  • Pass the resulting data to metrics, time-series charts, and other dashboard widgets. section 6.1.4

A simple Streamlit range panel

Use st.date_input twice and return both values: start = st.date_input("Start date", value=THIRTY_DAYS_AGO); end = st.date_input("End date", value=LATEST_DATE). The returned date values can feed the dashboard’s range-filtering function. section 6.3.2

Figure 6.12 Date range inputs displayed in a sidebar (see chapter_06/in_progress_06 in the GitHub repo for the full code).

View the sidebar layout showing how the two date inputs appear alongside the dashboard. section 6.3.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines Streamlit inputs, defaults, date types, and pandas filtering, stopping at widget construction and range filtering.
Examples
Uses a thirty-day default range, a hardcoded latest dataset date, sidebar inputs, and filtered sales rows.
What it assumes
Teaches date inputs, datetime values, and range filtering while assuming a basic dashboard and pandas workflow.
What you can do after
Build it from scratch with Streamlit date inputs and pass selected dates into pandas range filtering.
How it connects
Connects dashboard filters, pandas data preparation, data wrangling, and time-series charts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.