Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 42 ยท Projects and Practice

Project: A Sales Dashboard

Build a complete sales dashboard in Plotly with pandas: simulated data, KPI indicators, a trend with moving average, category bars, a region heatmap and one combined figure.

In this project you will build a one-page sales dashboard: headline numbers at the top, a monthly trend, a category comparison and a region-by-month heatmap, all in one figure that you can export as HTML. You will use almost everything from the previous chapters: subplots, annotations, hover templates and exports.

The data is simulated with a fixed random seed, so every run gives the same numbers and no real company data is used. The same code works unchanged if you replace step 1 with pd.read_csv("sales.csv").

Step 1: create and check the data

A good dashboard starts with a tidy table: one row per order, with a date, a region, a category and the amounts. Always look at the data before plotting.

Python Step 1: simulated orders

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

If this were real data you would also check for missing values and duplicates (orders.isna().sum(), orders.duplicated().sum()). Revenue is mostly driven by laptops and phones, so the category chart will be interesting.

Step 2: summaries with pandas

Charts should be fed with already aggregated tables. Plotly can aggregate some things, but pandas is clearer and keeps the figure small.

Python Step 2: the four tables the dashboard needs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice avg3, a three-month rolling mean: it smooths the noise so the trend reads clearly. The heatmap table has one row per region and one column per month.

Step 3: build the dashboard figure

The layout is a 3-row grid. The top row holds three Indicator cells (a KPI is a number with a label and, optionally, a delta against a reference). The middle row has the trend (wide) and category bars. The bottom row has the heatmap across the full width.

flowchart TB
    subgraph R1["Row 1: KPIs"]
        K1["Revenue"] --- K2["Orders"] --- K3["Average order"]
    end
    subgraph R2["Row 2"]
        T["Monthly trend + 3-month average"] --- C["Revenue by category"]
    end
    subgraph R3["Row 3"]
        H["Region x month heatmap"]
    end
    R1 --> R2 --> R3

The grid for the finished dashboard.

Indicators need cells of type "indicator". Everything else is xy, except that the heatmap spans two columns.

Python Step 3: the combined dashboard (figure structure)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

To see the picture, save it with fig.write_html("dashboard.html") on your own machine (see exporting and embedding). The dashboard below shows the finished layout in Plotly.js with the same kind of data, using a compact version of the figure so you can interact with it right here.

The finished layout in Plotly.js

Step 4: polish

  • Titles say the finding, not the chart type: "Revenue keeps growing, with a strong Q4" tells the reader what to see. Add it with fig.add_annotation.
  • One color story. Use a single blue family for revenue, and an accent (orange) only for the thing you want noticed.
  • Hover templates. fig.update_traces(hovertemplate="%{x|%b %Y}<br>$%{y:,.0f}<extra></extra>", selector=dict(type="bar")).
  • Annotate events such as a campaign month with fig.add_vrect.
  • Export. fig.write_html("dashboard.html", include_plotlyjs="cdn") gives a small shareable file.

Where to go from here

Replace the simulated table with a real CSV. Then, if viewers need filters (date range, region), turn the same figure functions into callbacks in a Dash app: the code that builds each figure stays the same, only the input table changes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the project aggregate the data with pandas before plotting?

    Charts built from small summary tables load faster and are easier to verify than charts built from thousands of raw rows.
  2. 2. Which spec makes a cell hold a KPI number?

    Indicator traces have no axes and need their own cell type.
  3. 3. What is the purpose of the 3-month rolling average?

    A rolling mean averages neighboring months, which reduces noise.
  4. 4. Why is the dataset generated with a fixed random seed?

    A seeded generator produces the same sequence each time, which makes examples and tests repeatable.

Summary

  • Start with tidy data, check it, then aggregate into small tables for each chart.
  • make_subplots with specs builds KPI, trend, bar and heatmap panels in one figure.
  • Rolling means smooth trends; titles should state the finding; colors should tell one story.
  • Export with write_html, or reuse the figure code inside Dash callbacks for interactive filters.

Next: Project: Stock Prices and Time Series