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

[Docs] Add documentation for the AgGrid #324

Merged
merged 162 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
96b6259
Minimal viable AGGrid implementation
maxschulz-COL Jan 10, 2024
a74a28f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2024
4878865
Improve MVP
maxschulz-COL Jan 11, 2024
e27c329
Merge branch 'main' into feature/enable_AG_grid
maxschulz-COL Jan 11, 2024
f9e14cb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 11, 2024
7d370c2
Remove super().__init__ and property
maxschulz-COL Jan 11, 2024
c4229ea
Inital styling of AGGrid
maxschulz-COL Jan 16, 2024
648294d
Add icons
maxschulz-COL Jan 16, 2024
4d63d9c
Left align left column
maxschulz-COL Jan 16, 2024
ac212b3
Proper deselect, hover, select behaviour for header
maxschulz-COL Jan 16, 2024
7e40f37
Base custom theme on existing alpine theme
maxschulz-COL Jan 17, 2024
64a4eb9
Initial commit with rendering Grid
maxschulz-COL Jan 24, 2024
67b12e6
First implementation of separate model approach
maxschulz-COL Jan 25, 2024
61d190e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2024
07ef9d0
Merge branch 'main' into feat/aggrid_separate_models
maxschulz-COL Jan 25, 2024
15928e6
First series of PR comments
maxschulz-COL Jan 29, 2024
c186d91
Initial PR ready implementation
maxschulz-COL Feb 19, 2024
eeb2c68
Merge main
maxschulz-COL Feb 20, 2024
923be67
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
69a7b07
Linting
maxschulz-COL Feb 20, 2024
d81b1c8
Small updates to grid model
maxschulz-COL Feb 20, 2024
8703d0e
Remove ununsed files
maxschulz-COL Feb 20, 2024
7a72572
Merge branch 'feat/aggrid_separate_models' into feat/aggrid_styling
maxschulz-COL Feb 20, 2024
58bb8b9
Change prettier settings
stichbury Feb 20, 2024
cb585a3
Remove underscores
stichbury Feb 19, 2024
770e65c
Add docs to gitignore
stichbury Feb 20, 2024
520a581
Fix broken internal links
stichbury Feb 20, 2024
3fcbab3
Implement default class
maxschulz-COL Feb 20, 2024
3df98f0
Switch base theme to ag-grid-quartz
maxschulz-COL Feb 20, 2024
d686f97
Fix broken links
stichbury Feb 20, 2024
dd375f7
Fix broken links
stichbury Feb 20, 2024
db2d92d
Add changelog
stichbury Feb 20, 2024
e355f55
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
9b1ac36
Update vizro-core/src/vizro/models/types.py
stichbury Feb 20, 2024
ca1072a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
b739a9f
Styling of filter manu
maxschulz-COL Feb 20, 2024
ef54cc1
Clean up file
maxschulz-COL Feb 20, 2024
4e3339d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
dcd3d57
Add flex and minWidth
maxschulz-COL Feb 20, 2024
68d1214
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
f145764
Update vizro-core/docs/pages/user-guides/tabs.md
stichbury Feb 20, 2024
4ac0c72
Update vizro-core/src/vizro/models/types.py
stichbury Feb 20, 2024
35dd30b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
d6aff5a
add changelog for vizro-core
stichbury Feb 20, 2024
16f2e4b
Merge branch 'second-branch-docs-name-changes' of https://github.com/…
stichbury Feb 20, 2024
695b6fd
Delete commented lines
maxschulz-COL Feb 20, 2024
18d4038
Roll back content in changelog files
stichbury Feb 20, 2024
6df1448
Merge branch 'feat/aggrid_styling' into docs/aggrid_docs_2
maxschulz-COL Feb 20, 2024
4bfe12c
Set header height to 40px
maxschulz-COL Feb 20, 2024
16ec94b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2024
a0daabc
First version of AG Grid docs
maxschulz-COL Feb 21, 2024
81da772
Modify table docs accordingly
maxschulz-COL Feb 21, 2024
0418eea
Adjust docs on custom tables
maxschulz-COL Feb 21, 2024
d607c49
Add Jo as docs CODEOWNERS
maxschulz-COL Feb 21, 2024
4e3b430
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2024
f36ab9a
fix small typo
maxschulz-COL Feb 21, 2024
a5b4f2c
Merge branch 'second-branch-docs-name-changes' into docs/aggrid_docs_2
maxschulz-COL Feb 21, 2024
e642da1
Change name from Grid to AGGrid
maxschulz-COL Feb 21, 2024
97fca21
Merge main into branch
maxschulz-COL Feb 21, 2024
b92f0eb
First batch of PR comments
maxschulz-COL Feb 22, 2024
fed22b4
Merge branch 'main' into feat/aggrid_separate_models
maxschulz-COL Feb 22, 2024
251b4bc
Merge branch 'main' into feat/aggrid_separate_models
maxschulz-COL Feb 22, 2024
dab8c8e
Add changelog
maxschulz-COL Feb 22, 2024
3b5bc2b
Merge branch 'feat/aggrid_separate_models' into feat/aggrid_styling
maxschulz-COL Feb 22, 2024
fd2bd82
Merge branch 'feat/aggrid_styling' of github.com:mckinsey/vizro into …
maxschulz-COL Feb 22, 2024
4d05653
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2024
63f3e84
Switch column sizing to defaults
maxschulz-COL Feb 22, 2024
a4ea384
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2024
4c80445
Merge branch 'main' into feat/aggrid_styling
huong-li-nguyen Feb 22, 2024
a2e1327
Merge branch 'main' into feat/aggrid_styling
huong-li-nguyen Feb 22, 2024
dd7c3df
Turn off pagination
maxschulz-COL Feb 22, 2024
4c81098
Merge branch 'feat/aggrid_separate_models' into feat/aggrid_styling
maxschulz-COL Feb 22, 2024
930700a
Merge branch 'feat/aggrid_styling' of github.com:mckinsey/vizro into …
maxschulz-COL Feb 22, 2024
0872fe2
Merge main
maxschulz-COL Feb 22, 2024
e3e6fc1
Merge branch 'feat/aggrid_styling' into docs/aggrid_docs_2
maxschulz-COL Feb 22, 2024
ccd9815
Merge remote-tracking branch 'origin/feat/aggrid_separate_models' int…
huong-li-nguyen Feb 22, 2024
842e68d
Replace datatable placeholder with aggrid
maxschulz-COL Feb 22, 2024
3a5123f
First PR comments
maxschulz-COL Feb 22, 2024
7a1c087
Merge branch 'feat/aggrid_separate_models' into feat/aggrid_styling
maxschulz-COL Feb 22, 2024
cad670b
Merge branch 'feat/aggrid_styling' into docs/aggrid_docs_2
maxschulz-COL Feb 22, 2024
1cab466
Further PR comments
maxschulz-COL Feb 22, 2024
7842fce
Further PR comments
maxschulz-COL Feb 22, 2024
4d3ac34
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2024
9ed2d4e
COnsolidate Table guides into one page
maxschulz-COL Feb 22, 2024
50dfae7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2024
fa53ea2
Remaining PR comments
maxschulz-COL Feb 22, 2024
1ce60f6
PR comment on Errors
maxschulz-COL Feb 23, 2024
0c897b3
Merge branch 'main' into feat/aggrid_separate_models
maxschulz-COL Feb 23, 2024
574e0f1
Fix unit tests after model refactoring
maxschulz-COL Feb 23, 2024
c019521
Schema
maxschulz-COL Feb 23, 2024
7935a27
Merge branch 'main' into feat/aggrid_separate_models
maxschulz-COL Feb 23, 2024
1d40cf3
Update requirements
maxschulz-COL Feb 23, 2024
56e9f25
Fix tests and take over most tests from Table
maxschulz-COL Feb 23, 2024
3d9abc8
Add attribute tests for Graph, Table and AgGrid
maxschulz-COL Feb 23, 2024
9c1751f
Introduce tests for dash_ag_grid function
maxschulz-COL Feb 23, 2024
f427e27
Add test for filter interaction of ag_grid
maxschulz-COL Feb 23, 2024
a7e8e8c
Add tests for dash_data_table
maxschulz-COL Feb 23, 2024
33dcb40
Rename aggrid.py file
maxschulz-COL Feb 23, 2024
c3ffc76
Rename _dash_files files
maxschulz-COL Feb 23, 2024
11c9cf5
Refactor constant names
maxschulz-COL Feb 23, 2024
602d0fe
Delete unnecessary assert in attribute tests
maxschulz-COL Feb 23, 2024
634b1e8
Use assert_component_equal in _dash_* tests
maxschulz-COL Feb 23, 2024
cabdafa
Reshuffle tests to make the category clearer
maxschulz-COL Feb 23, 2024
fb6f206
Remaining PR comments
maxschulz-COL Feb 23, 2024
08f5bc6
Merge branch 'main' into feat/aggrid_separate_models
maxschulz-COL Feb 27, 2024
24e0e84
PR comments Petar
maxschulz-COL Feb 27, 2024
637fae3
Merge branch 'feat/aggrid_separate_models' into feat/aggrid_styling
maxschulz-COL Feb 27, 2024
c0b9fc9
First round of Li PR comments
maxschulz-COL Feb 27, 2024
5e9ee30
First round of Li PR comments (2)
maxschulz-COL Feb 27, 2024
0bc4535
Styling of fly-out menu after PR comments
maxschulz-COL Feb 27, 2024
ec85e0c
Fix bug for missing ID when no actions but ID are defined
maxschulz-COL Feb 27, 2024
7ad99e1
Merge branch 'feat/aggrid_separate_models' into feat/aggrid_styling
maxschulz-COL Feb 27, 2024
65f3f08
Final CSS changes
maxschulz-COL Feb 27, 2024
decf2af
Merge branch 'main' into feat/aggrid_styling
maxschulz-COL Feb 27, 2024
59ce579
Merge branch 'feat/aggrid_styling' into docs/aggrid_docs_2
maxschulz-COL Feb 27, 2024
1c206ff
PR comments docs
maxschulz-COL Feb 27, 2024
b7c81ff
Modify demo and feature dashboards
maxschulz-COL Feb 28, 2024
1240151
Extend column length of example
maxschulz-COL Feb 28, 2024
b0240aa
Update vizro-core/docs/pages/user-guides/custom-tables.md
maxschulz-COL Feb 28, 2024
828ec18
Update vizro-core/docs/pages/user-guides/custom-tables.md
maxschulz-COL Feb 28, 2024
7fcd8eb
Update vizro-core/docs/pages/user-guides/custom-tables.md
maxschulz-COL Feb 28, 2024
48d9b86
Update vizro-core/docs/pages/user-guides/custom-tables.md
maxschulz-COL Feb 28, 2024
08ee157
Update vizro-core/docs/pages/user-guides/custom-tables.md
maxschulz-COL Feb 28, 2024
ec65d04
Update vizro-core/docs/pages/user-guides/custom-tables.md
maxschulz-COL Feb 28, 2024
dc175c0
Update vizro-core/docs/pages/user-guides/table.md
maxschulz-COL Feb 28, 2024
83dbbaa
Update vizro-core/docs/pages/user-guides/table.md
maxschulz-COL Feb 28, 2024
8a3763e
Update vizro-core/docs/pages/user-guides/table.md
maxschulz-COL Feb 28, 2024
8f1adaa
Update vizro-core/docs/pages/user-guides/table.md
maxschulz-COL Feb 28, 2024
7514eac
Update vizro-core/docs/pages/user-guides/table.md
maxschulz-COL Feb 28, 2024
9f179ee
Update vizro-core/docs/pages/user-guides/table.md
maxschulz-COL Feb 28, 2024
de2686c
Update vizro-core/docs/pages/user-guides/table.md
maxschulz-COL Feb 28, 2024
0a79f35
Update vizro-core/docs/pages/user-guides/custom-tables.md
maxschulz-COL Feb 28, 2024
b029733
Small stylistic change for docs
maxschulz-COL Feb 28, 2024
1e2f3e0
Fix table size and scrolling behaviour
maxschulz-COL Feb 29, 2024
1cd54e0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 29, 2024
4ff5d1c
Merge branch 'main' into feat/aggrid_styling
huong-li-nguyen Feb 29, 2024
91933be
Change to dark theme temporarily
huong-li-nguyen Feb 29, 2024
cea4fc0
Remove redundant container and add titles
huong-li-nguyen Feb 29, 2024
f6db92a
Fix CSS
huong-li-nguyen Feb 29, 2024
81effef
Implement quartz-dark theme
maxschulz-COL Feb 29, 2024
2f50960
Merge branch 'feat/aggrid_styling' of https://github.com/mckinsey/viz…
huong-li-nguyen Feb 29, 2024
7299808
Refactor CSS for buttons
huong-li-nguyen Feb 29, 2024
7ed6b89
Refactor and fix alignment
huong-li-nguyen Feb 29, 2024
6a96695
Apply correct color to radio-item and tidy
huong-li-nguyen Feb 29, 2024
b91793f
Add changelog
huong-li-nguyen Feb 29, 2024
88b7fc3
Fix tests
huong-li-nguyen Feb 29, 2024
e5d897f
Merge branch 'main' into feat/aggrid_styling
huong-li-nguyen Feb 29, 2024
6759f9f
Turn on pagination by default
huong-li-nguyen Feb 29, 2024
3c8963c
Improve scroll bar
huong-li-nguyen Feb 29, 2024
882ba28
Tidy and fix pagination
huong-li-nguyen Feb 29, 2024
821a5bf
Fix scrollbars
huong-li-nguyen Feb 29, 2024
47fa6b6
Remove requirement for ID in dash_data_table and dash_ag_grid
maxschulz-COL Feb 29, 2024
d8abbd2
Renaming of variables
maxschulz-COL Feb 29, 2024
99fe5f8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 29, 2024
5488cf9
Merge branch 'main' into feat/aggrid_styling
maxschulz-COL Mar 1, 2024
6ca06d7
Fix remaining unwanted CSS hover color
huong-li-nguyen Mar 1, 2024
b0ca6de
Remove unused properties
huong-li-nguyen Mar 1, 2024
cccd02a
Lint
huong-li-nguyen Mar 1, 2024
9530f92
Merge branch 'feat/aggrid_styling' into docs/aggrid_docs_2
maxschulz-COL Mar 1, 2024
43909de
Screenshots and small edits
maxschulz-COL Mar 1, 2024
c6b099a
Add changelog
maxschulz-COL Mar 1, 2024
9ac9dbc
Merge branch 'main' into docs/aggrid_docs_2
maxschulz-COL Mar 1, 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
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* @Joseph-Perkins @antonymilne @huong-li-nguyen @maxschulz-COL @Anna-Xiong
vizro-ai/docs/ @stichbury
vizro-core/docs/ @stichbury
12 changes: 7 additions & 5 deletions vizro-core/docs/pages/user-guides/custom-tables.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# How to create custom tables
# How to create custom Dash AG Grids and Dash DataTables

If you want to use the [`Table`][vizro.models.Table] model to and to create a custom [table](table.md) you can create your own custom table, e.g. when requiring computations that can be controlled by parameters.
In case that the available arguments for the [`AgGrid`][vizro.models.AgGrid] or [`Table`][vizro.models.Table] models are not sufficient,
there is always the possibility to create a custom Dash AG Grid or Dash DataTable.
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
One reason could be that you want to create a table/grid that requires computations that can be controlled by parameters (see below example).

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
For this, similar to how one would create a [custom chart](../user-guides/custom-charts.md), simply do the following:

- define a function that returns a `dash_table.DataTable` object
- decorate it with the `@capture("table")` decorator
- define a function that returns a `dash_ag_grid.AgGrid` or `dash_table.DataTable` object
- decorate it with the `@capture("ag_grid")` or `@capture("table")` decorator respectively
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
- the function must accept a `data_frame` argument (of type `pandas.DataFrame`)
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
- the table should be derived from and require only one `pandas.DataFrame` (e.g. any further dataframes added through other arguments will not react to dashboard components such as `Filter`)
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved

The following example shows a possible version of a custom table. In this case the argument `chosen_columns` was added, which you can control with a parameter:

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
??? example "Custom Dash DataTable"
Expand Down
315 changes: 303 additions & 12 deletions vizro-core/docs/pages/user-guides/table.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,316 @@
# How to use tables

This guide shows you how to use tables to visualize your data in the dashboard.
This guide shows you how to visualize tables in Vizro.

The [`Table`][vizro.models.Table] model allows you to visualize data in a tabular format.
There are two ways to visualize tables in Vizro, using either [AG Grid](#ag-grid) or [Dash DataTable](#dash-datatable).
In general, [AG Grid](#ag-grid) is Vizro's recommended table implementation, but in some cases it may make sense to use the [Dash DataTable](#dash-datatable) instead.

To add a [`Table`][vizro.models.Table] to your page, do the following:
## How to choose between AG Grid and Dash DataTable

- insert the [`Table`][vizro.models.Table] model into the `components` argument of the
Vizro offers two models - the [`AgGrid`][vizro.models.AgGrid] model and the [`Table`][vizro.models.Table] model - for the above two approaches respectively.
They both visualize tabular data in similar ways.

The main difference between the two is that the [`AgGrid`][vizro.models.AgGrid] model is based on plotly's [Dash AG Grid](https://dash.plotly.com/dash-ag-grid) component,
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
while the [`Table`][vizro.models.Table] model is based on the [Dash DataTable](https://dash.plotly.com/datatable) component.

Both approaches have similar base features, and are configurable in similar ways. However, the AG Grid offers more advanced features out-of-the-box, is more customizable
and also ships a powerful enterprise version. This is why it is Vizro's recommended table implementation. At the same time, the Dash DataTable can be used if developers are
already familiar with it, or if some custom functionality is easier to implement using the Dash DataTable.


## AG Grid

[AG Grid](https://www.ag-grid.com/) is an interactive table/grid component designed for viewing, editing, and exploring large datasets. It
is Vizro's recommended table implementation.

The Vizro [`AgGrid`][vizro.models.AgGrid] model is based on the [Dash AG Grid](https://dash.plotly.com/dash-ag-grid), which is in turn based the
original [Javascript implementation](https://www.ag-grid.com/).

### Basic usage

To add a [`AgGrid`][vizro.models.AgGrid] to your page, do the following:

- insert the [`AgGrid`][vizro.models.AgGrid] model into the `components` argument of the
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
[`Page`][vizro.models.Page] model
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
- enter any of the currently available table functions
- enter the `dash_ag_grid` function under the `figure` argument (imported via `from vizro.tables import dash_ag_grid`)
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved

The Vizro version of this AG Grid differs in one way from the original Dash AG Grid: it requires the user to provide a pandas dataframe as source of data.
This must be entered under the argument `data_frame`. All other [parameters of the Dash AG Grid](https://dash.plotly.com/dash-ag-grid/reference) can be entered as keyword arguments.
Note that some defaults are set for some of the arguments (e.g. for `columnDefs`) to help with styling and usability.

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved

!!! example "Basic Dash AG Grid"
=== "app.py"
```py
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid

df = px.data.gapminder()

page = vm.Page(
title="Example of a Dash AG Grid",
components=[
vm.AgGrid(title="Dash AG Grid", figure=dash_ag_grid(data_frame=df)),
],
controls=[vm.Filter(column="continent")],
)
dashboard = vm.Dashboard(pages=[page])

Vizro().build(dashboard).run()
```
=== "app.yaml"
```yaml
# Still requires a .py to register data connector in Data Manager and parse yaml configuration
# See from_yaml example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
title: Dash AG Grid
type: ag_grid
controls:
- column: continent
type: filter
title: Example of a Dash AG Grid
```
=== "Result"
[![Table]][Table]

See below for an overview of currently supported table functions.
[Table]: ../../assets/user_guides/table/table.png

### Dash DataTable
### Formatting columns

The [Dash DataTable](https://dash.plotly.com/datatable) is an interactive table component designed for viewing, editing, and exploring large datasets.
#### Numbers

One of the most common tasks when working with tables is to format the columns so that displayed numbers are more readable.
In order to do this, you can use the native functionality of [Value Formatters](https://dash.plotly.com/dash-ag-grid/value-formatters)
or the Vizro pre-defined [Custom Cell Data Types](https://dash.plotly.com/dash-ag-grid/cell-data-types#providing-custom-cell-data-types) as shown below.

The available custom cell types for Vizro are `dollar`, `euro`, `percentage` and `numeric`.

In order to use these, define your desired `<COLUMN>` alongside the chosen `cellDataType` in
the `columnDefs` argument of your `dash_ag_grid` function:

You can use the [Dash DataTable](https://dash.plotly.com/datatable) in Vizro by importing
```py
from vizro.tables import dash_data_table
columnDefs = [{"field": "<COLUMN>", "cellDataType": "euro"}]
```

In the below example we select and format some columns of the gapminder dataset.
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
??? example "AG Grid with formatted columns"
=== "app.py"
```py
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid

df = px.data.gapminder()

columnDefs = [{"field": "country"}, {"field": "year"}, {"field": "lifeExp", "cellDataType": "numeric"},
{"field": "gdpPercap", "cellDataType": "dollar"}, {"field": "pop", "cellDataType": "numeric"}]

page = vm.Page(
title="Example of AG Grid with formatted columns",
components=[
vm.AgGrid(
title="AG Grid with formatted columns",
figure=dash_ag_grid(
data_frame=df,
columnDefs=columnDefs,
),
)
],
)

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

Vizro().build(dashboard).run()
```
=== "app.yaml"
```yaml
# Still requires a .py to register data connector in Data Manager and parse yaml configuration
# See from_yaml example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
columnDefs:
- field: country
- field: year
- field: lifeExp
cellDataType: numeric
- field: gdpPercap
cellDataType: dollar
- field: pop
cellDataType: numeric
title: AG Grid with formatted columns
type: ag_grid
title: Example of AG Grid with formatted columns
```
=== "Result"
[![Table2]][Table2]

[Table2]: ../../assets/user_guides/table/styled_table.png

#### Dates

In order for the [`AgGrid`][vizro.models.AgGrid] model to sort and filter dates correctly, the date must either be of
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
string format `yyyy-mm-dd` (see [Dash AG Grid docs](https://dash.plotly.com/dash-ag-grid/date-filters#example:-date-filter))
or a pandas datetime object. Any pandas datetime column will be transformed into the `yyyy-mm-dd` format automatically.

#### Objects/Strings

No specific formatting is available for custom objects and strings, however you can make use of [Value Formatters](https://dash.plotly.com/dash-ag-grid/value-formatters)
in order to format e.g. displayed strings automatically.
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved


### Styling/Modifying the AG Grid

As mentioned above, all [parameters of the Dash AG Grid](https://dash.plotly.com/dash-ag-grid/reference) can be entered as keyword arguments. Below you can find
an example of a styled AG Grid where some conditional formatting is applied, and where the columns are editable, but not filterable or resizable.
There are many more ways to alter the grid beyond this showcase.

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
??? example "Styled and modified Dash AG Grid"
=== "app.py"
```py
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid

df = px.data.gapminder()

cellStyle = {
"styleConditions": [
{
"condition": "params.value < 1045",
"style": {"backgroundColor": "#ff9222"},
},
{
"condition": "params.value >= 1045 && params.value <= 4095",
"style": {"backgroundColor": "#de9e75"},
},
{
"condition": "params.value > 4095 && params.value <= 12695",
"style": {"backgroundColor": "#aaa9ba"},
},
{
"condition": "params.value > 12695",
"style": {"backgroundColor": "#00b4ff"},
},
]
}

columnDefs = [
{"field": "country"},
{"field": "continent"},
{"field": "year"},
{
"field": "lifeExp",
"valueFormatter": {"function": "d3.format('.1f')(params.value)"},
},
{
"field": "gdpPercap",
"valueFormatter": {"function": "d3.format('$,.1f')(params.value)"},
"cellStyle": cellStyle,
},
{
"field": "pop",
"valueFormatter": {"function": "d3.format(',.0f')(params.value)"},
},
]

page = vm.Page(
title="Example of Modified Dash AG Grid",
components=[
vm.AgGrid(
title="Modified Dash AG Grid",
figure=dash_ag_grid(
data_frame=df,
columnDefs=columnDefs,
defaultColDef={"resizable": False, "filter": False, "editable": True},
),
)
],
)

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

Vizro().build(dashboard).run()
```
=== "app.yaml"
```yaml
# Still requires a .py to register data connector in Data Manager and parse yaml configuration
# See from_yaml example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
columnDefs:
- field: country
- field: continent
- field: year
- field: lifeExp
valueFormatter:
function: "d3.format('.1f')(params.value)"
- field: gdpPercap
valueFormatter:
function: "d3.format('$,.1f')(params.value)"
cellStyle:
styleConditions:
- condition: params.value < 1045
style:
backgroundColor: "#ff9222"
- condition: params.value >= 1045 && params.value <= 4095
style:
backgroundColor: "#de9e75"
- condition: params.value > 4095 && params.value <= 12695
style:
backgroundColor: "#aaa9ba"
- condition: params.value > 12695
style:
backgroundColor: "#00b4ff"
- field: pop
type: rightAligned
valueFormatter:
function: "d3.format(',.0f')(params.value)"
defaultColDef:
resizable: false
filter: false
editable: true
title: Dash AG Grid
type: ag_grid
title: Example of a Dash AG Grid
```
=== "Result"
[![Table2]][Table2]

[Table2]: ../../assets/user_guides/table/styled_table.png

If the available arguments are not sufficient, there is always the option to create a [custom AG Grid callable](custom-tables.md).

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
## Dash DataTable

Similar to AG Grid, the [Dash DataTable](https://dash.plotly.com/datatable) is an interactive table/grid component designed for viewing, editing, and exploring large datasets.

In general, we recommend using [AG Grid](#ag-grid) for tables unless you have a particular reason to prefer Dash DataTable.

The Vizro [`Table`][vizro.models.Table] model is based on the [Dash DataTable](https://dash.plotly.com/datatable).

maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
### Basic usage

To add a [`Table`][vizro.models.Table] to your page, do the following:

- insert the [`Table`][vizro.models.Table] model into the `components` argument of the
[`Page`][vizro.models.Page] model
- enter the `dash_data_table` function under the `figure` argument (imported via `from vizro.tables import dash_data_table`)

The Vizro version of this table differs in one way from the original table: it requires the user to provide a pandas dataframe as source of data.
This must be entered under the argument `data_frame`.
All other [parameters of the Dash DataTable](https://dash.plotly.com/datatable/reference) can be entered as keyword arguments. Note that we are
Expand Down Expand Up @@ -63,7 +354,7 @@ setting some defaults for some of the arguments to help with styling.

[Table]: ../../assets/user_guides/table/table.png

#### Styling/Modifying the Dash DataTable
### Styling/Modifying the Dash DataTable

As mentioned above, all [parameters of the Dash DataTable](https://dash.plotly.com/datatable/reference) can be entered as keyword arguments. Below you can find
an example of a styled table where some conditional formatting is applied. There are many more ways to alter the table beyond this showcase.
Expand Down Expand Up @@ -193,4 +484,4 @@ an example of a styled table where some conditional formatting is applied. There

[Table2]: ../../assets/user_guides/table/styled_table.png

To enhance existing tables, please see our How-to-guide on creating [custom tables](custom-tables.md).
If the available arguments are not sufficient, there is always the option to create a [custom Dash DataTable](custom-tables.md).
Loading
Loading