Py.Cafe

huong-li-nguyen/

simple-kpi-card

Single Vizro KPI card inside Dash

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
# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples
# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples

import dash_bootstrap_components as dbc
import pandas as pd
from dash import Dash, html
from vizro.figures.library import kpi_card, kpi_card_reference

df_kpi = pd.DataFrame({"Actual": [100, 200, 700], "Reference": [100, 300, 500], "Category": ["A", "B", "C"]})

app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container(
    [
        html.H1(children="Title of Dash App"),
        html.Div(
            children=[
                kpi_card_reference(
                    data_frame=df_kpi,
                    value_column="Actual",
                    reference_column="Reference",
                    title="Sales",
                    value_format="{value:.2f}€",
                    reference_format="{delta:+.2f}€ vs. last year ({reference:.2f}€)",
                ),
            ],
        ),
    ]
)