Project 20: Plotly Data Dashboard 📊¶

Difficulty: 🔴 Advanced

Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/plotly_data_dashboard/.

← Back to index

Description¶

Build a multi-chart interactive dashboard with Plotly — hover, zoom, and pan across linked visualizations.

Libraries & Modules¶

  • plotly.graph_objects, plotly.subplots.make_subplots
  • pandas — data manipulation
  • numpy — synthetic dataset

Python Concepts You'll Practice¶

Subplots, interactive widgets, HTML export, data pipelines

🎛️ Parameter Variations¶

  • NUM_ROWS — dataset size
  • CATEGORIES — pie/bar segments
  • COLOR_SCALE — 'Viridis', 'Plasma', 'Tealrose'
  • CHART_THEME — 'plotly', 'plotly_dark', 'ggplot2'
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline

from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame

OUTPUT_DIR = Path("outputs") / "plotly_data_dashboard"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\plotly_data_dashboard

Step 1 — Build synthetic dataset¶

In [3]:
import numpy as np
import pandas as pd

# 🎛️ TWEAK THESE
NUM_ROWS = 200
CATEGORIES = ["Python", "Data", "Web", "ML", "Automation"]
SEED = 42

np.random.seed(SEED)
df = pd.DataFrame({
    "day": pd.date_range("2026-01-01", periods=NUM_ROWS, freq="D"),
    "users": np.cumsum(np.random.poisson(15, NUM_ROWS)) + np.random.randint(50, 100),
    "revenue": np.cumsum(np.random.normal(120, 40, NUM_ROWS)).clip(0),
    "category": np.random.choice(CATEGORIES, NUM_ROWS),
    "satisfaction": np.random.uniform(3.5, 5.0, NUM_ROWS).round(1),
})
df.head()
Out[3]:
day users revenue category satisfaction
0 2026-01-01 81 93.738842 ML 4.6
1 2026-01-02 91 182.575633 ML 3.7
2 2026-01-03 107 267.691482 Data 3.7
3 2026-01-04 126 360.850526 Web 3.9
4 2026-01-05 137 494.288475 Web 3.9

Step 2 — Interactive multi-panel dashboard¶

In [4]:
import plotly.graph_objects as go
from plotly.subplots import make_subplots

# 🎛️ TWEAK THESE
COLOR_SCALE = "Tealrose"
CHART_THEME = "plotly_dark"

cat_counts = df["category"].value_counts()

fig = make_subplots(
    rows=2, cols=2,
    subplot_titles=("User Growth", "Revenue Trend", "Category Mix", "Satisfaction Distribution"),
    specs=[[{"type": "scatter"}, {"type": "scatter"}],
           [{"type": "pie"}, {"type": "histogram"}]],
)

fig.add_trace(go.Scatter(x=df["day"], y=df["users"], mode="lines", name="Users",
    line=dict(color="#00d2ff", width=2)), row=1, col=1)
fig.add_trace(go.Scatter(x=df["day"], y=df["revenue"], mode="lines", name="Revenue",
    line=dict(color="#ff6b6b", width=2), fill="tozeroy"), row=1, col=2)
fig.add_trace(go.Pie(labels=cat_counts.index, values=cat_counts.values, hole=0.4,
    marker=dict(colors=["#6c5ce7", "#00b894", "#fdcb6e", "#e17055", "#74b9ff"])), row=2, col=1)
fig.add_trace(go.Histogram(x=df["satisfaction"], nbinsx=15, marker_color="#a29bfe"), row=2, col=2)

fig.update_layout(
    title_text="CodeItAll — Interactive Data Dashboard",
    template=CHART_THEME,
    height=700,
    showlegend=False,
)

out = OUTPUT_DIR / "plotly_dashboard.html"
fig.write_html(str(out))
print(f"Dashboard saved: {out.resolve()}")
display(HTML(out.read_text(encoding="utf-8")))
Dashboard saved: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\plotly_data_dashboard\plotly_dashboard.html

✅ Project complete¶

Check your output folder: outputs/plotly_data_dashboard/

← Back to index