import pandas as pd
import vizro.actions as va
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
df = pd.read_csv("h1_sales.csv")
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
daily_revenue_container = vm.Container(
title="Daily revenue",
components=[
vm.Graph(
figure=px.density_heatmap(
df,
x="week",
y="day_of_week",
z="revenue", # sum of revenue per cell,
nbinsx=df["week"].nunique(),
marginal_x="histogram",
category_orders={"day_of_week": days},
labels={"revenue": "Revenue ($)", "price": "Price ($)", "day_of_week": "Day"},
),
actions=[
va.set_control(control="week_filter", value="x"),
va.set_control(control="day_filter", value="y"),
],
header="This heatmap shows the aggregated revenue for each day of the week across H1. Click on a cell to "
"show all the day's transactions in the table below.",
),
],
collapsed=False,
variant="filled",
)
individual_transactions_container = vm.Container(
layout=vm.Flex(),
title="Individual transactions",
description="**Data source**: h1_sales.csv.\n\n**Last updated**: 2025-09-18.",
components=[
vm.Button(
icon="Download",
text="Download data",
actions=va.export_data(targets=["grid"]),
),
vm.AgGrid(
id="grid",
figure=dash_ag_grid(
df,
columnDefs=[
{"field": "product"},
{"field": "price", "cellDataType": "dollar"},
{"field": "quantity"},
{"field": "revenue", "cellDataType": "dollar"},
],
),
),
],
controls=[
vm.Filter(id="week_filter", column="week", selector=vm.Dropdown(multi=False), show_in_url=True),
vm.Filter(
id="day_filter",
column="day_of_week",
selector=vm.Dropdown(title="Day", options=days), # Put days in manually to get ordered correctly.
show_in_url=True,
),
],
variant="outlined",
)
page = vm.Page(
title="Analysis of H1 sales",
layout=vm.Flex(),
components=[daily_revenue_container, individual_transactions_container],
)
dashboard = vm.Dashboard(theme="vizro_light", pages=[page])
Vizro().build(dashboard).run()