Interactive Dashboards With Streamlit and Plotly

Matplotlib remains a valuable Python library for statistical charts, scientific figures and publication-quality visualizations. However, many analytics projects require more than a chart that users can view but cannot explore.
Imagine presenting monthly sales performance to a business manager. A static bar chart might show total revenue, but the manager may also want to filter results by region, compare product categories, inspect individual months and investigate unusual changes. Producing a separate chart for every question quickly becomes inefficient.
This is where Streamlit and Plotly offer a more flexible approach.
Streamlit helps developers build data applications using Python, while Plotly provides interactive visualizations that respond to user exploration. Combined, they can transform an existing analysis into a dashboard that supports faster investigation and clearer business decisions.
For data analysts, Python developers and aspiring data professionals, learning these tools is a practical step toward building portfolio projects
Matplotlib is excellent for creating controlled, customizable visualizations. Its limitation is not chart quality; it is that interactive application features often require additional development.
Capability | Matplotlib | Plotly + Streamlit |
Static chart creation | Excellent | Supported |
Hover details and zooming | Requires additional interaction tools | Built into Plotly charts |
Interactive filters | Requires additional interface code | Streamlit widgets |
Dashboard layout | Requires a separate application layer | Built into Streamlit |
Python-based development | Yes | Yes |
Web application deployment | Requires a hosting approach | Designed for Python data apps |
Streamlit supports Matplotlib figures through st.pyplot() and interactive Plotly figures through st.plotly_chart(). You do not have to abandon Matplotlib; the right choice depends on the task.
Use Matplotlib when you need publication-ready charts or controlled static figures. Choose Plotly and Streamlit when users need to explore data, change filters and interact with a complete analytical interface.
Streamlit: The dashboard framework
Streamlit provides layouts, sidebar controls, text, tables, file uploads and interactive widgets. Developers can create a web application using Python without building every interface component from scratch.
Official documentation: Streamlit Docs
Plotly: The interactive charting library
Plotly creates interactive line charts, bar charts, scatter plots, heatmaps, maps and other visualizations. Readers can inspect points, zoom into regions and explore additional chart details.
Official documentation: Plotly Python
Together, these tools separate the interface from the visualization logic. Streamlit manages the controls and layout, while Plotly handles chart construction and interaction.
Start by installing the required packages.
pip install streamlit plotly pandas
Create a file named app.py. The following example builds a small sales dashboard with a regional filter, KPI metrics and an interactive revenue chart.
import pandas as pd
import plotly.express as px
import streamlit as st
st.set_page_config(page_title="Sales Dashboard", layout="wide")
st.title("Sales Performance Dashboard")
@st.cache_data
def load_data():
return pd.DataFrame({
"Month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jan", "Feb", "Mar", "Apr", "May", "Jun"],
"Region": ["North"] 6 + ["South"] 6,
"Revenue": [12000, 14500, 13800, 16200, 17500, 19000,
10000, 11800, 12500, 14000, 15500, 16800],
"Orders": [120, 135, 128, 150, 160, 175,
100, 112, 120, 132, 145, 155]
})
df = load_data()
region = st.sidebar.selectbox(
"Choose region", ["All"] + sorted(df["Region"].unique())
)
filtered = df if region "All" else df[df["Region"] region]
revenue = filtered["Revenue"].sum()
orders = filtered["Orders"].sum()
col1, col2 = st.columns(2)
col1.metric("Total Revenue", f"${revenue:,.0f}")
col2.metric("Total Orders", f"{orders:,}")
monthly = (
filtered.groupby("Month", as_index=False)
.agg(Revenue=("Revenue", "sum"))
)
fig = px.line(
monthly, x="Month", y="Revenue",
markers=True, title="Monthly Revenue"
)
fig.update_layout(hovermode="x unified")
st.plotly_chart(fig, width="stretch")
st.dataframe(filtered, width="stretch")
A useful dashboard should help users answer questions, not simply display attractive charts.
For a sales dashboard, consider adding:
Date filters: Compare performance across selected periods.
Category filters: Identify products contributing most to revenue.
Regional comparisons: Investigate differences across locations.
KPI cards: Display revenue, orders, average order value and growth.
Detailed tables: Allow users to inspect the records behind an aggregate.
Plotly supports many chart types, so you can choose a visualization that matches the analytical question. A line chart is useful for trends, a bar chart for comparisons and a scatter plot for relationships between variables.
When implementing filters, ensure that every KPI and chart uses the same filtered dataset unless the dashboard explicitly communicates a different calculation.
For business reporting, define metrics carefully. For example, average order value should generally be calculated as total revenue divided by the number of qualifying orders, not as an unweighted average of monthly averages.
Streamlit reruns the Python script when users interact with widgets. This makes development straightforward, but repeatedly loading large files or querying a database can slow down the interface.
Use these practices to keep dashboards responsive:
Cache reusable data-loading and transformation functions with @st.cache_data.
Use @st.cache_resource for suitable shared resources such as database connections or machine-learning models.
Filter and aggregate data before rendering large charts.
Avoid unnecessary chart traces and excessively detailed datasets.
Use clear labels, sensible defaults and readable tooltips.
Test the dashboard on mobile and desktop screens.
Caching also needs careful consideration when data changes frequently. Set appropriate expiration rules or implement explicit refresh behavior when users need recent information.
For larger applications, use pagination, query-level filtering or pre-aggregated datasets instead of transferring every database record into the browser.
A local dashboard is a useful prototype, but sharing it with colleagues or customers introduces operational requirements.
Before deployment, check that dependencies are documented, data sources are available in the hosting environment and secrets are not embedded in the source code.
Streamlit Community Cloud is one option for deploying eligible applications from a GitHub repository. Other hosting environments may be more suitable for private enterprise applications or workloads with specific infrastructure requirements. See the Streamlit deployment documentation for current options.
For production dashboards, consider:
Authentication and authorization.
Secure handling of database credentials.
Data refresh schedules and failure reporting.
Logging, monitoring and dependency updates.
Access controls for sensitive records.
Testing with realistic data volumes.
One important distinction: Plotly's interactive charts and Streamlit's dashboard widgets do not automatically provide every possible application interaction. For example, complex cross-filtering driven by chart hover events may require a different event-handling architecture. If you need highly customized, event-driven interactions, evaluate Plotly Dash as an alternative.
For learners building data analytics portfolios, a dashboard becomes more compelling when it demonstrates the complete analytical workflow.
Include a clearly defined business problem, data-cleaning steps, metric definitions, interactive visualizations and a concise explanation of the findings. Document any assumptions and distinguish sample data from genuine results.
A sales dashboard could answer which regions contribute the most revenue, how monthly performance changes and which categories need further investigation. A student performance dashboard could compare scores across subjects while protecting individual student information.
The goal is to show that you can transform data into a usable decision-support tool—not merely call a plotting function.
Use Streamlit for the interface and Plotly for charts that benefit from interaction.
Cache expensive operations and measure performance with realistic datasets.
Make KPI definitions consistent across filters and visualizations.
Use appropriate chart types instead of forcing every question into a line chart.
Include documentation, deployment instructions and data-security considerations in portfolio projects.
Loading or recalculating large datasets on every interaction without caching.
Displaying too many charts without a clear analytical purpose.
Using inconsistent metric calculations across dashboard sections.
Exposing database credentials or confidential records.
Assuming that an interactive chart automatically provides full application-level filtering and state management.
1. What is the difference between Streamlit and Plotly?
Streamlit is a Python framework for building data applications and user interfaces. Plotly is a visualization library for creating interactive charts. They work together to build dashboards.
2. Can I use Plotly without Streamlit?
Yes. Plotly charts can be used in Python notebooks, standalone HTML exports and web applications, including applications built with Dash.
Plotly
3. Is Streamlit better than Matplotlib for dashboards?
Streamlit is useful for building complete interactive dashboard interfaces, while Matplotlib is well suited to static, customized charts. They can also be used together in the same application.
4. Can I deploy a Streamlit and Plotly dashboard online?
Yes. You can deploy a dashboard through supported hosting platforms, provided you configure its dependencies, data access, secrets and security requirements correctly.
5. Do Streamlit and Plotly work with real-time data?
They can display frequently refreshed data when connected to suitable data sources and refresh mechanisms. The appropriate implementation depends on the required update frequency, dataset size and application architecture.
Matplotlib remains an important part of Python data visualization, but modern analytics often requires interfaces that users can explore. Streamlit simplifies dashboard development, while Plotly adds interactive charts that make data investigation more flexible.
By combining filters, consistent KPIs, efficient data processing and secure deployment practices, developers can turn Python analyses into practical applications. For aspiring data analysts and software developers, a well-documented interactive dashboard is also a valuable way to demonstrate technical skills and business understanding.
The best starting point is a small project with a clear question, a manageable dataset and a handful of meaningful visualizations. Expand it only when each new feature helps users make better decisions.
Written by
Alaffiya Madarwala
Last updated
29 October 2026
