Interactive Dashboards with Plotly
Static charts show a single view. Interactive charts let users hover, zoom, and filter to explore the data themselves.
a. Introduction to Plotly
Plotly is a library for making interactive charts. Users can hover over points to see values, zoom into areas, and click legends to hide or show series. This makes data easier to explore.
The easiest way to use it is through Plotly Express, a simple interface that creates a full chart in one line. You need to install it first with pip install plotly.
import plotly.express as px
fig = px.bar(df, x="region", y="sales", title="Sales by Region")
fig.show()The chart opens in your notebook or browser. Plotly works well with Pandas DataFrames, so you can pass your data straight in.
b. Building Interactive Charts
Plotly Express supports many chart types, including line charts, scatter plots, pie charts, and histograms. Each one is a single function call.
fig = px.line(df, x="month", y="sales", color="region", markers=True)
fig = px.scatter(df, x="price", y="sales", size="quantity", hover_name="product")Options like color, size, and hover_name add extra detail without extra code. You can also use facet_col to split one chart into several smaller ones by category.
You can customize the layout with fig.update_layout(). Change titles, fonts, colors, and sizes to match your style. Keep each chart focused on one message.
c. Combining Charts into a Dashboard
A dashboard brings several charts together on one page. With Plotly, you can place multiple charts in a grid using make_subplots.
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Bar(x=df["region"], y=df["sales"]), row=1, col=2)For full dashboards with dropdowns, sliders, and live updates, use Dash, a framework from the Plotly team. Streamlit is another popular choice that is simple to learn.
Plan your layout before building. Put the most important numbers at the top, add filters on the side, and group related charts together. A clean layout matters more than the number of charts.
d. Sharing Your Dashboard
The simplest way to share a Plotly chart is to save it as an HTML file. Anyone can open it in a browser, and it stays fully interactive.
fig.write_html("sales_dashboard.html")For dashboards built with Dash or Streamlit, you can deploy them to a hosting service so others can open them with a link. Streamlit Community Cloud and similar services offer free options for small projects.
You can also export charts as images using fig.write_image(), which needs the kaleido package. Use images for reports and presentations, and HTML or hosted apps when you want people to interact.
Data Analysis with Python Handbook
Wesline Rinisha








