import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.figures import kpi_card
from vizro.tables import dash_ag_grid
from dash import html
from vizro.models.types import capture
import pandas as pd
tips = px.data.tips
@capture("figure")
def dynamic_html_header(data_frame: pd.DataFrame, column: str) -> html.H2:
"""Creates a HTML header that dynamically updates based on controls."""
return html.H2(f"We are looking at the data for {data_frame[column].iloc[0]}! ☕ ⛅")
page = vm.Page(
title="KPI Indicators",
layout=vm.Layout(
grid=[
[2, 2, 2, 2],
[0, -1, -1, -1]
] + [[1, 1, 1, 1]] * 4),
components=[
vm.Figure(
figure=kpi_card(
data_frame=tips,
value_column="tip",
value_format="${value:.2f}",
icon="shopping_cart",
title="KPI Card I",
)
),
vm.AgGrid(figure=dash_ag_grid(data_frame=tips)),
vm.Figure(figure=dynamic_html_header(data_frame=tips, column="day"))
],
controls=[vm.Filter(column="day", selector=vm.RadioItems())],
)
dashboard = vm.Dashboard(pages=[page])
app = Vizro().build(dashboard).dash