A small dashboard
Last updated
The report answers your question once. A small dashboard lets readers ask the next one themselves: how did my region do, for my kind of rice, in the years I care about? In this lesson you'll plan a dashboard around one question, build it in Streamlit with two filters and three charts, and test it on someone who hasn't seen your work.
By the end of this lesson you can
- Plan a dashboard around one repeated question
- Build it in Streamlit from the capstone's clean data
- Test it on a reader, and cut what they don't use
Plan it
Write the plan in the README before writing code (10.3):
- Who: readers of your report who want their own region.
- The question: "How have rice prices moved in my region, against the country?"
- Filters: two. For rice: the kind of rice, and the regions. For rain: the month, and a range of years. For schools: the level, and the regions.
- Charts: three, each answering part of the question. For rice: the real price over time, the change on a year earlier, and the gap from the national average.
Anything else goes in the report, not the dashboard.
Build it
dashboard.py reads the clean, analysed data that 05-answer.ipynb writes (add a to_csv at its end). A starting point for the rice question, using Altair (7.9) for the charts:
import altair as alt import pandas as pd import streamlit as st @st.cache_data def load(): rice = pd.read_csv("data/clean/rice_real.csv", parse_dates=["month"]) # written by 05-answer return rice rice = load() st.title("Rice prices by region") st.caption("Source: Philippine Statistics Authority, OpenSTAT (CC BY). Real pesos, base month as in the report.") kind = st.sidebar.selectbox("Rice", sorted(rice["rice"].unique())) all_regions = sorted(rice["region"].unique()) regions = st.sidebar.multiselect("Regions", all_regions, default=all_regions[:1]) if not regions: st.warning("Choose at least one region.") st.stop() chosen = rice[(rice["rice"] == kind) & rice["region"].isin(regions)] price = alt.Chart(chosen).mark_line().encode(x="month:T", y=alt.Y("real_price:Q", title="real pesos a kilo"), color="region:N") st.subheader("Real price") st.altair_chart(price) change = alt.Chart(chosen).mark_line().encode(x="month:T", y=alt.Y("yoy_%:Q", title="% on a year earlier"), color="region:N") st.subheader("Change on a year earlier") st.altair_chart(change) gap = alt.Chart(chosen).mark_bar().encode(x=alt.X("mean(gap):Q", title="pesos above the national average"), y="region:N") st.subheader("Gap from the national average, whole period") st.altair_chart(gap)
(.venv) $ streamlit run dashboard.py
- The caption gives the source and the licence on the page itself (C.1): CC BY needs the credit wherever the data appears.
- Real pesos are labelled as such, with the base month the report uses. A reader comparing this with a news report's nominal price needs to know.
All three prepared questions use data you may share, with credit. If you brought your own data and its terms don't allow sharing it, the dashboard is for your own use, or shows only what you're allowed to publish: summaries rather than daily values, for example.
Test it
Ask someone who hasn't seen your work to answer one question with it ("How did prices in your region move in 2024, against the country?"), without your help. Watch, and don't explain. Then:
- Anything they didn't find, make easier to find.
- Anything they misread, fix: labels, titles, units.
- Anything they never used, consider taking off.
Write down what changed, in the README. A dashboard that one person can use unaided is ready to share with the report.
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Streamlit: st.altair_chart: showing an Altair chart
- Streamlit: st.cache_data: loading the data once
- Vega-Altair: Overview: declarative charts in Python