Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add Figure model and introduce KPI card functions #493

Merged
merged 79 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
fb37101
Add KPI Card based on Plotly indicator
huong-li-nguyen May 21, 2024
9428969
Add KPI Card based on custom component
huong-li-nguyen May 21, 2024
c2c3710
Refine and leave some comments
huong-li-nguyen May 21, 2024
dbba0dd
Get dynamic Card working quickly
huong-li-nguyen May 21, 2024
a3ca6f6
Add logic to enable `text_card` and `nav_card`
huong-li-nguyen May 22, 2024
521954a
Tidy
huong-li-nguyen May 22, 2024
1081cd2
Lint
huong-li-nguyen May 22, 2024
4ceeed8
Add partially styled KPI
huong-li-nguyen May 22, 2024
1ca2be2
Simplify dynamic styled card
huong-li-nguyen May 22, 2024
bba9e01
Tidy
huong-li-nguyen May 22, 2024
e1a2858
Add styling to mkd card
huong-li-nguyen May 22, 2024
8309d9f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2024
7edfec2
Add another KPI style
huong-li-nguyen May 22, 2024
c65678e
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen May 22, 2024
798d8ef
Lint
huong-li-nguyen May 22, 2024
c01a3db
Add comments
huong-li-nguyen May 23, 2024
6062063
Tidy CSS
huong-li-nguyen May 23, 2024
67d41aa
Make sample page with 3 pre-selected designs
huong-li-nguyen May 23, 2024
6eedfe7
Move `dbc.Card` to `build` and remove id provision
huong-li-nguyen May 30, 2024
f3b1d6a
Refactor classNames for `kpi_card_icon`
huong-li-nguyen May 30, 2024
feaf493
Refactor simple and icon KPI card to one
huong-li-nguyen May 30, 2024
466b252
Refactor classNames for `kpi_card_ref`
huong-li-nguyen May 30, 2024
35f64aa
Refactor and tidy some more
huong-li-nguyen May 30, 2024
284f2ba
Add formatting arguments to function for discussion
huong-li-nguyen May 30, 2024
eb2c9c6
Enable coloring of higher-level card
huong-li-nguyen May 30, 2024
456eb29
Improve naming
huong-li-nguyen May 30, 2024
3f87ac9
Remove remaining `kpi-card-icon` reference
huong-li-nguyen May 30, 2024
67321aa
Tidy app
huong-li-nguyen May 30, 2024
3aab16b
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen May 30, 2024
289ada3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
9f37512
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen Jun 4, 2024
1c7eb6e
Update docstrings
huong-li-nguyen Jun 4, 2024
1554541
Return `dbc.Card` inside `CapturedCallable`
huong-li-nguyen Jun 5, 2024
98b8c1e
Replace `kpi_card` with suggested improvement
huong-li-nguyen Jun 5, 2024
26ce1be
Replace `kpi_card_ref` with suggested
huong-li-nguyen Jun 5, 2024
3ef65f2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
a1b1228
Remove redundant code from previous iterations
huong-li-nguyen Jun 5, 2024
4309315
Lint
huong-li-nguyen Jun 5, 2024
90dfcb3
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen Jun 5, 2024
faabc46
Commit this
huong-li-nguyen Jun 5, 2024
6bf46d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
b005f51
Revert changes in card
huong-li-nguyen Jun 5, 2024
e964bb6
Create higher-level `Figure` model
huong-li-nguyen Jun 5, 2024
5c31faf
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen Jun 5, 2024
7161d15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
2a92af6
Revert unwanted changes
huong-li-nguyen Jun 5, 2024
ae3e57b
Tidy
huong-li-nguyen Jun 5, 2024
d0bce82
Fix renaming
huong-li-nguyen Jun 5, 2024
ac56dba
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen Jun 5, 2024
b6515ff
Tidy CSS
huong-li-nguyen Jun 5, 2024
bed23b4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 5, 2024
4c6969f
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen Jun 6, 2024
acccea1
Add docstrings to kpi card functions
huong-li-nguyen Jun 6, 2024
a344db5
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen Jun 6, 2024
72343be
Implement reverse-color coding via CSS
huong-li-nguyen Jun 7, 2024
c5c7368
Update schema
huong-li-nguyen Jun 7, 2024
8062991
Add changelog
huong-li-nguyen Jun 7, 2024
fda4a5e
Add ignore for custom format warning
huong-li-nguyen Jun 7, 2024
de649ee
Tidy redundant TODOs
huong-li-nguyen Jun 7, 2024
ec4a45b
Add unit tests for `Figure`
huong-li-nguyen Jun 7, 2024
95ebf91
Add empty doc file for now
huong-li-nguyen Jun 7, 2024
6f5b33d
Revert changes in `vizro-ai`
huong-li-nguyen Jun 7, 2024
4c71bdc
Add relevant updates in docs
huong-li-nguyen Jun 7, 2024
104b99c
Fix doc warning for now
huong-li-nguyen Jun 7, 2024
9d53cbb
Update schema
huong-li-nguyen Jun 7, 2024
f0d0304
Update components.md
stichbury Jun 7, 2024
8883285
Change icon and apply lowercase
huong-li-nguyen Jun 7, 2024
0e5fa7d
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen Jun 7, 2024
f07e7d1
Incorporate PR comments
huong-li-nguyen Jun 11, 2024
09ceea1
Fix height due to added container
huong-li-nguyen Jun 11, 2024
5fbfe84
Replace output with function call
huong-li-nguyen Jun 12, 2024
db8ac58
Add constants for defaults and tidy html divs
huong-li-nguyen Jun 12, 2024
41c4ca5
Handle ZeroDivisonError
huong-li-nguyen Jun 12, 2024
782127c
Simplify docstrings for `getitem` and remove TODO
huong-li-nguyen Jun 12, 2024
cea7a61
Add more context to docstrings of kpi card functions
huong-li-nguyen Jun 12, 2024
36c6a4f
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen Jun 17, 2024
68cf51e
Change container className
huong-li-nguyen Jun 17, 2024
769a314
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen Jun 18, 2024
ee606f8
Incorporate last PR comments
huong-li-nguyen Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

### Highlights ✨

Copy link
Contributor Author

@huong-li-nguyen huong-li-nguyen Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder for myself to update this with the relevant links when docs are ready

- Introduce `Figure` as a new `Page` component, enabling all dash components to be reactive in
`Vizro`. See the [user guide on figure](XXXX) for more information. ([#493](https://github.com/mckinsey/vizro/pull/493))
- Introduce styled KPI cards to be used inside `Figure`. See the [user guide on KPI cards](XXXX) for more information. ([#493](https://github.com/mckinsey/vizro/pull/493))

<!--
### Removed

- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Added

- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
11 changes: 9 additions & 2 deletions vizro-core/docs/pages/API-reference/captured-callables.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Table functions

<!-- vale off -->
# Table functions

API reference for all pre-defined [`CapturedCallable`][vizro.models.types.CapturedCallable] table functions to be used in the
[`AgGrid`][vizro.models.AgGrid] and [`Table`][vizro.models.Table] models. Visit the how-to guide on [tables](../user-guides/table.md)
Expand All @@ -10,5 +9,13 @@ for more information.
options:
show_source: true

# Figure functions
API reference for all pre-defined [`CapturedCallable`][vizro.models.types.CapturedCallable] figure functions to be used in the
[`Figure`][vizro.models.Figure]. Visit the how-to guide on [figures](../user-guides/figure.md)
for more information.

::: vizro.figures
options:
show_source: true

<!-- vale on -->
18 changes: 13 additions & 5 deletions vizro-core/docs/pages/user-guides/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,46 @@ listed below to fill your dashboard with visuals.

Use graphs to visualize your data with any Plotly chart.

[:octicons-arrow-right-24: View User Guide](graph.md)
[:octicons-arrow-right-24: View user guide](graph.md)

- :material-table-large:{ .lg .middle } __Table__

---

Use tables to visualize your tabular data.

[:octicons-arrow-right-24: View User Guide](table.md)
[:octicons-arrow-right-24: View user guide](table.md)

- :material-cards-outline:{ .lg .middle } __Card & button__

---

Use cards and buttons to visualize text, navigate to different URLs or attach any [action](actions.md).

[:octicons-arrow-right-24: View User Guide](card-button.md)
[:octicons-arrow-right-24: View user guide](card-button.md)

- :material-graph:{ .lg .middle } __Figure__

---

Use figure to visualize your make any dash component reactive.

[:octicons-arrow-right-24: View user guide](figure.md)

- :octicons-table-16:{ .lg .middle } __Container__

---

Use containers to group your page components into sections and subsections.

[:octicons-arrow-right-24: View User Guide](container.md)
[:octicons-arrow-right-24: View user guide](container.md)

- :material-tab-plus:{ .lg .middle } __Tabs__

---

Use tabs to group your containers and navigate between them.

[:octicons-arrow-right-24: View User Guide](tabs.md)
[:octicons-arrow-right-24: View user guide](tabs.md)

</div>
2 changes: 1 addition & 1 deletion vizro-core/docs/pages/user-guides/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A static data source is the simplest way to send data to your dashboard and shou

### Supply directly

You can directly supply a pandas DataFrame into components such as [graphs](graph.md) and [tables](table.md).
You can directly supply a pandas DataFrame into components such as [graphs](graph.md), [tables](table.md) and [figures](figure.md).

The below example uses the Iris data saved to a file `iris.csv` in the same directory as `app.py`. This data can be generated using `px.data.iris()` or [downloaded](../../assets/user_guides/data/iris.csv).

Expand Down
1 change: 1 addition & 0 deletions vizro-core/docs/pages/user-guides/figure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# How to use figures
huong-li-nguyen marked this conversation as resolved.
Show resolved Hide resolved
105 changes: 87 additions & 18 deletions vizro-core/examples/_dev/app.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,100 @@
"""Example to show dashboard configuration."""
"""Dev app to try things out."""

petar-qb marked this conversation as resolved.
Show resolved Hide resolved
import pandas as pd
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid, dash_data_table
from vizro.figures import kpi_card, kpi_card_reference

df = px.data.gapminder()
df = pd.DataFrame([[67434, 65553, "A"], [6434, 6553, "B"], [34, 53, "C"]], columns=["Actual", "Reference", "Category"])

page_one = vm.Page(
title="Dash AG Grid",
layout=vm.Layout(grid=[[0, 1]], col_gap="0px"),
page = vm.Page(
title="KPI Indicators",
layout=vm.Layout(grid=[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, -1]]),
components=[
vm.AgGrid(title="Equal Title One", figure=dash_ag_grid(data_frame=df)),
vm.Graph(figure=px.box(df, x="continent", y="lifeExp", title="Equal Title One")),
# Style 1: Value Only
vm.Figure(figure=kpi_card(data_frame=df, value_column="Actual", title="Value I", agg_func="sum")),
vm.Figure(figure=kpi_card(data_frame=df, value_column="Actual", title="Value II", agg_func="mean")),
vm.Figure(figure=kpi_card(data_frame=df, value_column="Actual", title="Value III", agg_func="median")),
# Style 2: Value and reference value
vm.Figure(
figure=kpi_card_reference(
data_frame=df,
value_column="Reference",
reference_column="Actual",
title="Ref. Value II",
agg_func="sum",
)
),
vm.Figure(
figure=kpi_card_reference(
data_frame=df,
value_column="Actual",
reference_column="Reference",
title="Ref. Value I",
agg_func="sum",
)
),
vm.Figure(
id="kpi-card-reverse-coloring",
figure=kpi_card_reference(
data_frame=df,
value_column="Actual",
reference_column="Reference",
title="Ref. Value III",
agg_func="median",
icon="shopping_cart",
),
),
# Style 3: Value and icon
vm.Figure(
figure=kpi_card(
data_frame=df,
value_column="Actual",
icon="shopping_cart",
title="Icon I",
agg_func="sum",
value_format="${value:.2f}",
)
),
vm.Figure(
figure=kpi_card(
data_frame=df,
value_column="Actual",
icon="payment",
title="Icon II",
agg_func="mean",
value_format="{value:.0f}€",
)
),
vm.Figure(
figure=kpi_card(
data_frame=df,
value_column="Actual",
icon="monitoring",
title="Icon III",
agg_func="median",
)
),
# This should still work without a figure argument
vm.Card(
text="""
# Text Card
Hello, this is a text card.
"""
),
vm.Card(
text="""
# Nav Card
Hello, this is a nav card.
""",
href="https://www.google.com",
),
],
controls=[vm.Filter(column="Category")],
)

page_two = vm.Page(
title="Dash Data Table",
layout=vm.Layout(grid=[[0, 1]]),
components=[
vm.Table(title="Equal Title One", figure=dash_data_table(data_frame=df)),
vm.Graph(figure=px.box(df, x="continent", y="lifeExp", title="Equal Title One")),
],
)
dashboard = vm.Dashboard(pages=[page_one, page_two])

dashboard = vm.Dashboard(pages=[page])

if __name__ == "__main__":
Vizro().build(dashboard).run()
16 changes: 3 additions & 13 deletions vizro-core/examples/_dev/assets/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
#logo {
height: 40px;
margin-left: -8px;
}

/* Apply styling to parent */
.card:has(#my-card) {
background-color: white;
}

/* Apply styling to children */
#my-card p {
color: black;
/* Apply reverse color logic via CSS */
#kpi-card-reverse-coloring .card-kpi:has(.color-neg) {
border-left: 4px solid #1a85ff;
Copy link
Contributor Author

@huong-li-nguyen huong-li-nguyen Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of how we can color code in reverse, see comment here: #505 (comment)

}
1 change: 1 addition & 0 deletions vizro-core/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nav:
- Overview: pages/user-guides/components.md
- Graphs: pages/user-guides/graph.md
- Tables: pages/user-guides/table.md
- Figures: pages/user-guides/figure.md
- Cards & buttons: pages/user-guides/card-button.md
- Containers: pages/user-guides/container.md
- Tabs: pages/user-guides/tabs.md
Expand Down
4 changes: 3 additions & 1 deletion vizro-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ filterwarnings = [
# Ignore until pandas 3 is released:
"ignore:(?s).*Pyarrow will become a required dependency of pandas:DeprecationWarning",
# Ignore until plotly fixes so the warning is no longer raised:
"ignore:When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group:FutureWarning"
"ignore:When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group:FutureWarning",
# Ignore warning when providing a custom format string to the KPI Cards:
"ignore:Custom format string detected."
]
norecursedirs = ["tests/tests_utils", "tests/js"]
pythonpath = ["tests/tests_utils", "examples/kpi"]
28 changes: 28 additions & 0 deletions vizro-core/schemas/0.1.18.dev0.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@
"required": ["text"],
"additionalProperties": false
},
"Figure": {
"title": "Figure",
"description": "Creates a figure-like object that can be displayed in the dashboard and is reactive to controls.\n\nArgs:\n type (Literal[\"figure\"]): Defaults to `\"figure\"`.\n figure (CapturedCallable): Figure like object to be displayed. Defaults to `None`. For more information see\n available figure callables in `vizro.figures`.",
"type": "object",
"properties": {
"id": {
"title": "Id",
"description": "ID to identify model. Must be unique throughout the whole dashboard.When no ID is chosen, ID will be automatically generated.",
"default": "",
"type": "string"
},
"type": {
"title": "Type",
"default": "figure",
"enum": ["figure"],
"type": "string"
}
},
"additionalProperties": false
},
"Graph": {
"title": "Graph",
"description": "Wrapper for `dcc.Graph` to visualize charts in dashboard.\n\nArgs:\n type (Literal[\"graph\"]): Defaults to `\"graph\"`.\n figure (CapturedCallable): See [`CapturedCallable`][vizro.models.types.CapturedCallable].\n actions (List[Action]): See [`Action`][vizro.models.Action]. Defaults to `[]`.",
Expand Down Expand Up @@ -344,6 +364,7 @@
"button": "#/definitions/Button",
"card": "#/definitions/Card",
"container": "#/definitions/Container",
"figure": "#/definitions/Figure",
"graph": "#/definitions/Graph",
"table": "#/definitions/Table",
"tabs": "#/definitions/Tabs"
Expand All @@ -362,6 +383,9 @@
{
"$ref": "#/definitions/Container"
},
{
"$ref": "#/definitions/Figure"
},
{
"$ref": "#/definitions/Graph"
},
Expand Down Expand Up @@ -1135,6 +1159,7 @@
"button": "#/definitions/Button",
"card": "#/definitions/Card",
"container": "#/definitions/Container",
"figure": "#/definitions/Figure",
"graph": "#/definitions/Graph",
"table": "#/definitions/Table",
"tabs": "#/definitions/Tabs"
Expand All @@ -1153,6 +1178,9 @@
{
"$ref": "#/definitions/Container"
},
{
"$ref": "#/definitions/Figure"
},
{
"$ref": "#/definitions/Graph"
},
Expand Down
1 change: 0 additions & 1 deletion vizro-core/schemas/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
parser.add_argument("--check", help="check schema is up to date", action="store_true")
args = parser.parse_args()

# TODO: need to setup alias function to keep lowercase if wanted
schema_json = Dashboard.schema_json(indent=4, by_alias=False)
schema_path = Path(__file__).with_name(f"{__version__}.json")

Expand Down
4 changes: 4 additions & 0 deletions vizro-core/src/vizro/figures/__init__.py
huong-li-nguyen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from vizro.figures.kpi_cards import kpi_card, kpi_card_reference

# Please keep alphabetically ordered
__all__ = ["kpi_card", "kpi_card_reference"]
Loading
Loading