Skip to content

Creating Dashboards with Plotly

Dashboard idea

A โ€œdashboardโ€ can be as simple as:

  • a few key charts
  • shown together
  • with a consistent theme

Plotly supports multi-plot layouts via make_subplotsmake_subplots.

Example: 2 charts in one view

Subplots dashboard
import pandas as pd
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
 
sales = pd.DataFrame({
    "city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
    "sales": [120, 180, 90, 160],
})
 
trend = pd.DataFrame({
    "day": [1, 2, 3, 4, 5],
    "orders": [120, 140, 130, 160, 155],
})
 
bar = px.bar(sales, x="city", y="sales", title="Sales by city")
line = px.line(trend, x="day", y="orders", markers=True, title="Orders trend")
 
fig = make_subplots(rows=1, cols=2, subplot_titles=("Sales", "Orders"))
 
for trace in bar.data:
    fig.add_trace(trace, row=1, col=1)
for trace in line.data:
    fig.add_trace(trace, row=1, col=2)
 
fig.update_layout(title_text="Mini dashboard", showlegend=False)
fig.show()
Subplots dashboard
import pandas as pd
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
 
sales = pd.DataFrame({
    "city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
    "sales": [120, 180, 90, 160],
})
 
trend = pd.DataFrame({
    "day": [1, 2, 3, 4, 5],
    "orders": [120, 140, 130, 160, 155],
})
 
bar = px.bar(sales, x="city", y="sales", title="Sales by city")
line = px.line(trend, x="day", y="orders", markers=True, title="Orders trend")
 
fig = make_subplots(rows=1, cols=2, subplot_titles=("Sales", "Orders"))
 
for trace in bar.data:
    fig.add_trace(trace, row=1, col=1)
for trace in line.data:
    fig.add_trace(trace, row=1, col=2)
 
fig.update_layout(title_text="Mini dashboard", showlegend=False)
fig.show()

Next step

If you want a full web app dashboard, the next tool is usually Dash or Streamlit.

If this helped you, consider buying me a coffee โ˜•

Buy me a coffee

Was this page helpful?

Let us know how we did