Figure functions
Using figure functions in pure Dash app
Identical functions can also be used outside the Vizro framework in a pure Dash app by importing from the vizro.figures.library namespace:
vizro.figures
Built-in figure functions.
Usage documentation
kpi_card
kpi_card(
data_frame: DataFrame,
value_column: str,
*,
value_format: str = "{value}",
agg_func: str = "sum",
title: str | None = None,
icon: str | None = None
) -> Card
Creates a styled KPI (Key Performance Indicator) card displaying a value.
Warning
The format string provided to value_format is evaluated, so ensure that only trusted
user input is provided to prevent potential security risks.
| PARAMETER | DESCRIPTION |
|---|---|
data_frame
|
DataFrame containing the data.
TYPE:
|
value_column
|
Column name of the value to be shown.
TYPE:
|
value_format
|
Format string to be applied to the value. It must be a valid Python format string where any of the below placeholders can be used.
Common examples include:
TYPE:
|
agg_func
|
String function name to be used for aggregating the data. Common options include
TYPE:
|
title
|
KPI title displayed on top of the card. If not provided, it defaults to the capitalized
TYPE:
|
icon
|
Name of the icon from the Google Material Icon Library to be displayed on the left side of the KPI title. If not provided, no icon is displayed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Card
|
A Dash Bootstrap Components card ( |
Example
Source code in src/vizro/figures/library.py
kpi_card_reference
kpi_card_reference(
data_frame: DataFrame,
value_column: str,
reference_column: str,
*,
value_format: str = "{value}",
reference_format: str = "{delta_relative:+.1%} vs. reference ({reference})",
agg_func: str = "sum",
title: str | None = None,
icon: str | None = None,
reverse_color: bool = False
) -> Card
Creates a styled KPI (Key Performance Indicator) card displaying a value in comparison to a reference value.
Warning
The format string provided to value_format and reference_format is evaluated, so ensure that
only trusted user input is provided to prevent potential security risks.
| PARAMETER | DESCRIPTION |
|---|---|
data_frame
|
DataFrame containing the data.
TYPE:
|
value_column
|
Column name of the value to be shown.
TYPE:
|
reference_column
|
Column name of the reference value for comparison.
TYPE:
|
value_format
|
Format string to be applied to the value. It must be a valid Python format string where any of the below placeholders can be used.
Common examples include:
TYPE:
|
reference_format
|
Format string to be applied to the reference. For more details on possible placeholders,
see docstring on
TYPE:
|
agg_func
|
String function name to be used for aggregating the data. Common options include
TYPE:
|
title
|
KPI title displayed on top of the card. If not provided, it defaults to the capitalized
TYPE:
|
icon
|
Name of the icon from the Google Material Icon Library to be displayed on the left side of the KPI title. If not provided, no icon is displayed.
TYPE:
|
reverse_color
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Card
|
A Dash Bootstrap Components card ( |
Example
Source code in src/vizro/figures/library.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |