Key Takeaways: Streamlit Dashboards


  1. Apps are scripts. Streamlit's threshold concept is that a Streamlit app is a Python script that re-runs from top to bottom on every user interaction. No event handlers, no component lifecycles, no callbacks — just linear code. Internalize this and everything else makes sense.

  2. Widgets return values directly. value = st.slider(...) returns the current value as a Python object. You use the value in a regular Python flow: filter DataFrames, build charts, display results. The widget state is part of the widget's return value, not a separate state store.

  3. Caching makes re-runs fast. @st.cache_data for DataFrames and serializable data; @st.cache_resource for models and database connections. Without caching, expensive operations re-run on every interaction and the app is unusable. With caching, only the cheap parts of the script re-run.

  4. Layout is composable. st.sidebar, st.columns, st.tabs, st.expander, st.container — each is a simple primitive that you combine into dashboards. Sidebar for filters, columns for KPIs, tabs for different views, expanders for optional content.

  5. Every major chart library works. st.pyplot for matplotlib/seaborn, st.plotly_chart for Plotly, st.altair_chart for Altair, st.bokeh_chart for Bokeh, plus built-in st.line_chart and friends for quick cases. Bring whatever library you already know.

  6. Session state persists across re-runs. st.session_state is a dict-like object that survives re-runs for a user's session. Use for counters, multi-step workflows, persistent selections, and form values. Local variables do not persist; session state does.

  7. Forms batch interactions. st.form groups widgets so only a submit button triggers a re-run. Useful for dashboards with expensive downstream computations where you don't want every widget change to trigger a re-compute.

  8. Streamlit Community Cloud is free deployment. Push code to GitHub, connect to share.streamlit.io, wait a minute, get a URL. The deployment friction is effectively zero. Paid tiers exist for scale and private hosting.

  9. The filter-transform-display pattern is canonical. Most Streamlit dashboards have the same structure: sidebar filters → apply filters → compute derived metrics → display as charts and tables. Learn the pattern and most dashboards follow it.

  10. Streamlit has limits; know them. For complex cross-filtering, custom CSS, high-scale deployment, or specific enterprise features, Dash or other tools may be better. For everything else (which is most projects), Streamlit is the fastest path from data to interactive app.


Chapter 30 introduces Dash, the main alternative to Streamlit, with a different execution model (explicit callbacks) and different trade-offs. Knowing both tools lets you pick the right one for each project — Streamlit for speed and simplicity, Dash for flexibility and control.