Py.Cafe

maxi.schulz/

vizro-figure-showcase

Showcasing Figure component using tips DF

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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