liveBook · Manning

Chapter 6: A dashboard fit for a CEO

What you will learn in chapter 6 of Build Python Web Apps with Streamlit

This chapter introduces why executive metrics dashboards matter and previews building an interactive CEO KPI dashboard with Streamlit, pandas, caching, widgets, and Plotly.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces why executive metrics dashboards matter and previews building an interactive CEO KPI dashboard with Streamlit, pandas, caching, widgets, and Plotly.

Key terms: metrics, dashboard, key performance indicators, KPIs, pandas, caching, filters, widgets, Plotly, Streamlit

6.1 A metrics dashboard

Introduces the business need for a timely sales metrics dashboard and frames Streamlit as the tool for building it without burdening Engineering.

Key terms: metrics dashboard, daily sales data, Streamlit, Python framework, Engineering

6.1.1 Stating the concept

Defines the CEO dashboard as a decision-support view of sales data and key metrics for executives.

Key terms: dashboard, sales data, key metrics, executives

6.1.2 Defining the requirements

This section turns the CEO dashboard concept into a concrete data description, feature requirements, and deliberately limited first-release scope.

Key terms: sales_data.csv, CSV, sales, gross margin, transactions, primary key, total sales, margin percentage, average transaction value, filters

6.1.3 Visualizing the user experience

This section turns the dashboard requirements into a UI mock that prioritizes key metrics, filtering controls, and charts for trends and breakdowns.

Key terms: key metrics, UI mock, filters, date range selector, slice of the data, dimensions, cuts, time series chart, line chart, pie chart

6.1.4 Brainstorming the implementation

This section outlines the dashboard’s data flow, from loading and preparing CSV data through global filtering and visualization-specific transformations.

Key terms: raw data, CSV file, data preparation, global filters, filtered data, transformations, filter bar, date range selectors, global, widgets

6.2 Loading the data

This section introduces loading external CSV data into a Streamlit app, using pandas to hold and display it, and caching large data loads for performance.

Key terms: external source, CSV file, loading data, in memory, Streamlit, pandas, data manipulation, caching, performance, large data

6.2.1 The pandas library

This section introduces pandas through installing it, loading the sales CSV into a dataframe, inspecting its structure and types, and previewing selected columns.

Key terms: pip, pip show pandas, pandas, dataframe, import pandas as pd, pd.read_csv, sales_data.csv, type(), info(), object

6.2.2 Reading and displaying a dataframe

This section separates CSV loading into a module, builds a deployment-safe path to the file, and displays a dataframe preview in Streamlit while motivating caching.

Key terms: data_loader.py, dashboard.py, load_data, entry point, pandas dataframe, working directory, __file__, Path, pathlib, .resolve()

6.2.3 Caching data

This section uses st.cache_data to cache a dashboard’s loaded dataframe across reruns, refreshes, and users while controlling freshness and loading feedback.

Key terms: st.cache_data, cache, load_data, dataframe, rerun, @st.cache_data, decorator, data_loader.py, import streamlit as st, ttl

6.3 Prepping and filtering the data

This section introduces filtering the dashboard data into relevant slices using a filter panel and date range selector, supported by pandas data wrangling.

Key terms: filtering, rows of data, slices of the data, filter panel, date range selector, field values, pandas, data wrangling

6.3.1 Creating a filter panel

This section builds a polished multi-select filter panel that derives options from dashboard data and applies users’ selections to a dataframe.

Key terms: filter panel, st.multiselect, filter dimensions, get_unique_values, pandas dataframe, column selection, pandas series, .unique(), filter_panel, st.columns

6.3.2 Creating a date range selector

This section adds sidebar start/end date inputs and uses their selections to filter the dashboard dataframe efficiently by an inclusive date range.

Key terms: st.date_input, date_range_panel, start, end, LATEST_DATE, THIRTY_DAYS_AGO, timedelta, date.today(), date, prep_data

6.4 Calculating and displaying metrics

This section introduces business metrics as concise indicators of performance and previews calculating, configuring, and prominently displaying the metrics important to Note n’ Nib’s CEO.

Key terms: metrics, earnings, profit, revenue growth, customer acquisition cost, positive metric, negative metric, cost, Note n’ Nib, metrics configuration

6.4.1 Calculating the metrics

This section defines the dashboard’s four business metrics and shows how to calculate each from an aggregated slice of the sales data.

Key terms: total sales, gross margin, margin percentage, average transaction value, sales, transactions, source CSV, transaction, date

6.4.2 Setting up the metrics configuration

This section defines a flexible, configuration-driven way to describe dashboard metrics, their calculations, formatting, and display selection.

Key terms: configuration file, metric_config.py, general design, hardcoding, Metric, dataclass, title, type, func, callable

6.4.3 Formatting the metrics

This section defines how dashboard metric values are converted into concise display strings based on their configured metric types.

Key terms: Metric class, metric type, format_metric, dollars type, percent type, humanize, humanize.metric, cognitive load, fraction, percentage

6.4.4 Displaying the metrics

This section implements the dashboard’s bordered metric bar by rendering configured metrics in Streamlit columns and using a nested-column layout to center each metric.

Key terms: metric_bar, display_metrics, st.metric, display column, get_metric, Metric, func, dataframe, metric_cols, st.columns

6.5 Constructing visualizations

This section introduces why executive dashboards need visualizations and previews building time-series and breakdown charts with pandas, Plotly, and Streamlit.

Key terms: visualizations, graphs, tables of numbers, executives, line chart, pie chart, tracked metrics, chosen dimension, pandas, wrangle

6.5.1 Creating a time series chart

This section transforms filtered dashboard data into metric time series, builds interactive Plotly line charts, and presents one chart per metric in Streamlit tabs.

Key terms: time series, groupby, apply, lambda function, include_groups=False, reset_index, Plotly Graph Objects, go, Figure, go.Figure

6.5.2 Creating a pie chart

This section adds a donut-style pie chart that breaks additive dashboard metrics down by a selected dimension and places it beside the time-series chart.

Key terms: Total sales, Gross margin, Margin %, ATV, pie-chart-applicable metrics, get_metric_grouped_by_dimension, get_metric_time_series, dimension, group by, Day

6.6 Summary

This summary recaps the data loading, filtering, metric display, and visualization techniques used to build a Streamlit metrics dashboard.

Where this is used later

Concepts explained in this chapter

← Chapter 5: Sharing your apps with the world Chapter 7: The CEO strikes back: Supercharging the dashboard →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.