liveBook · Manning

Drilldown view

As explained in Build Python Web Apps with Streamlit

A drilldown view is an interface view that presents detailed data for selected dimensions, metrics, or subsets of a broader summary.

A dashboard can show a number without showing why it changed. A drilldown view gives a data-comfortable user a way to investigate beyond summary metrics and charts. Rather than crowding the main dashboard, it provides a detailed table for exploring selected dimensions and metrics. section 7.5 section 7.5.2

Investigating a sales question

Suppose a fountain-pen campaign targeted women in two older age groups. A chart can break sales down by age or by gender, but the question calls for both—and for a comparison between products. Selecting age group, gender, and product name as table dimensions makes that combination available for inspection. section 7.5.2

The table behaves like a flexible pivot table: users choose which dimensions define its rows, while key metrics appear together as columns. It shows aggregated values for each combination, not an unfiltered dump of source rows. With no dimensions selected, it shows metrics for the entire supplied dataframe. section 7.5.2 section 7.5.3

def get_aggregate_metrics(df, dimensions):
  if dimensions:
    grouped = df.groupby(dimensions)
    return grouped.apply(get_metric_cols).reset_index()
  metric_cols = get_metric_cols(df)
  return pd.DataFrame(metric_cols).T

The aggregation function groups a pandas dataframe by the selected dimensions and calculates metrics for each group. Its other branch handles an empty selection by returning one row of overall metrics. section 7.5.3

Build the interface incrementally: collect dimensions with a Streamlit multiselect, calculate each configured metric for every group, then display the result in a dataframe. Separate Main and Compare tabs show tables for their respective dataframes; an unavailable selection produces a warning instead of a table. section 7.5.3

Add a Total row calculated from the full dataframe, then format metric values and shade that row so it is easy to distinguish from the breakdown. Computing the total through the metric functions preserves their calculations rather than simply adding displayed group values. section 7.5.3

How Build Python Web Apps with Streamlit covers it

How deep it goes
Works through dimension selection, grouped metric calculation, total-row creation, formatting, and display, rather than stopping at a raw dataframe.
Examples
Uses a fountain-pen sales question involving product, age, and gender, plus Main and Compare tables with a formatted Total row.
What it assumes
Assumes some familiarity with pandas grouping and earlier dictionary comprehensions while recapping how configured metric functions become table values.
What you can do after
Build it from scratch with Streamlit and pandas to display selected dimension breakdowns, overall metrics, and a styled Total row.
How it connects
Connects dashboard metrics and charts to pivot tables, dataframe grouping, filters, and metric aggregation.

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.