Interactive Data Apps with Streamlit

Turn Python analysis into interactive web apps: widgets, layouts, charts, caching, session state, forms and multipage navigation, tested with AppTest and ready to deploy.

Intermediate · Data Science · about 16 hours · 5 modules · certificate on completion

Taught by Sebastiàn Vargàs, Camilà Torresè, AI Learning Companions.

About this course

Streamlit turns a Python script into a web app: add a slider and a chart, and anyone with a browser can explore your analysis. This course takes you from a first script to a tested, multipage app ready to deploy, building one app all the way through: an explorer of daily air-quality readings from four (made-up) monitoring stations. You'll start with how Streamlit works, rerunning the whole script on every interaction, and build the first version from text, widgets, metrics and a chart. Then you'll lay it out with a sidebar, columns and tabs, draw Altair charts with threshold lines, format tables with column_config and offer the filtered data as a download.

Next come the parts that make real apps work: caching data with st.cache_data and sharing a database connection with st.cache_resource, rerunning only part of a page with fragments, keeping values in session state, changing them safely with callbacks, and collecting community reports with a validated form stored in SQLite. Finally you'll split the app into pages with st.navigation, test every page with Streamlit's AppTest and pytest, smoke-test the server's health endpoint, and prepare deployment with a theme, secrets, requirements and a Dockerfile, or Streamlit Community Cloud. Every lab is checked by tests that run without a browser, and the capstone is a deployed data app of your own. It builds on Data Analysis with Python and pandas; AI-Powered Business Intelligence Fundamentals and Data Storytelling and Dashboard Design are good companions.

What you'll learn

  • Explain Streamlit's rerun model, and build apps from text and data elements and widgets
  • Lay out apps with the sidebar, columns and tabs, and show data with charts, configured tables, metrics and downloads
  • Speed apps up with st.cache_data, st.cache_resource and fragments, choosing the right one for each job
  • Keep state across reruns with session state, callbacks and forms, and store shared data in a database
  • Build multipage apps with st.navigation, test them with AppTest and pytest, and prepare them for deployment

Skills you'll gain

Streamlit, Interactive data apps, Caching, Session state, Forms and callbacks, Multipage apps, App testing, Deployment, Data visualisation

Tools

Python 3, Streamlit, pandas, Altair, pytest, SQLite, Docker, Streamlit Community Cloud

Before you start

Python and pandas: functions, modules, DataFrames, filtering and grouping, as in Data Analysis with Python and pandas. Data Visualisation with Matplotlib, Seaborn and Plotly helps with the charts. You need Python 3.10 or later; the course installs streamlit and pytest in a virtual environment and makes its data with a script. Docker and a GitHub account are optional, for deployment.

Modules

  1. Streamlit basics: scripts, elements and widgets

    See how Streamlit turns a Python script into a web app that reruns on every interaction, then build a first data app from text, data elements and widgets, and test it with AppTest.

    • How a Streamlit app runs (12 min)
    • Widgets: input that reruns the app (12 min)
    • Widget identity, keys and showing results (12 min)
    • Hands-on lab: Build and test a first data app
  2. Layout, charts and data display

    Arrange an app with the sidebar, columns, tabs and containers, choose between Streamlit's built-in charts and Altair, Plotly or Matplotlib, and present data with configured tables, metrics and downloads.

    • Layout: sidebar, columns, tabs and containers (12 min)
    • Charts: built-in, Altair, Plotly and Matplotlib (12 min)
    • Tables, metrics and downloads (12 min)
    • Hands-on lab: Lay out the explorer with tabs, charts and a download
  3. Caching and performance

    Stop the rerun model from repeating slow work: cache data with st.cache_data, share connections and models with st.cache_resource, and rerun only part of an app with fragments.

    • Caching data with st.cache_data (12 min)
    • Sharing resources with st.cache_resource (12 min)
    • Fragments and other speed-ups (12 min)
    • Hands-on lab: Cache the data, share a connection and add a fragment
  4. Session state, callbacks and forms

    Keep values across reruns with session state, change state safely with callbacks, and collect input with forms that submit in one go and store their results in a database.

    • Session state (12 min)
    • Callbacks and changing state safely (12 min)
    • Forms and dialogs (12 min)
    • Hands-on lab: Remember filters and collect reports with a form
  5. Multipage apps, testing and deployment

    Split the app into pages with st.navigation and shared filters, test every page with AppTest, and deploy it with its configuration and secrets to Streamlit Community Cloud or a Docker container.

    • Multipage apps with st.navigation (12 min)
    • Testing Streamlit apps (12 min)
    • Deploying: configuration, secrets and hosting (12 min)
    • Hands-on lab: Make the explorer multipage, test every page and prepare it for deployment

Project: Build and deploy a data app

A (fictional) city's environment team wants a public app where residents can explore air quality and send in their own readings, and you're building it. Start from the lab's explorer and air_quality.csv, or use a dataset of your own of a similar size (a few thousand rows at most), and build a multipage Streamlit app with st.navigation. It needs an overview page with KPI metrics and a trend chart; a detail page with a configured table, a second chart and a download; and a contribution page whose validated form stores entries in SQLite through a connection cached with st.cache_resource. Filters shared across pages live in session state, the data is cached with st.cache_data, and at least one part of a page is a fragment. Write at least six tests (pytest and AppTest), including one per page, and keep calculations in plain functions that are tested by import. Prepare it for deployment with a requirements.txt, a .streamlit/config.toml theme and any secrets read through st.secrets (nothing secret committed), then deploy it to Streamlit Community Cloud, or run it in Docker with the health check passing. Finish with a README that explains how to run, test and deploy it.

Part of

The products this course names are trademarks of their owners, who haven't made or endorsed it.

Start the course free