-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tidy] Return empty data frame from AgGrid, Table and Figure build me…
…thods (#644)
- Loading branch information
Showing
11 changed files
with
253 additions
and
215 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...og.d/20240821_165515_petar_pejovic_return_empty_data_frame_from_tables_build.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Highlights ✨ | ||
- A bullet item for the Highlights ✨ 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)) | ||
--> | ||
<!-- | ||
### 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 | ||
|
||
- Improve page loading time for `AgGrid`, `Table` and `Figure`. ([#644](https://github.com/mckinsey/vizro/pull/644)) | ||
|
||
<!-- | ||
### 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 | ||
|
||
- Fix persistence of `columnSize` and `selectedRows` for `AgGrid`. ([#644](https://github.com/mckinsey/vizro/pull/644)) | ||
|
||
<!-- | ||
### 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)) | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,139 @@ | ||
"""Dev app to try things out.""" | ||
|
||
import pandas as pd | ||
import vizro.models as vm | ||
import vizro.plotly.express as px | ||
from charts.charts import page2 | ||
from vizro import Vizro | ||
from vizro.actions import filter_interaction | ||
from vizro.figures import kpi_card | ||
from vizro.managers import data_manager | ||
from vizro.models.types import capture | ||
from vizro.tables import dash_ag_grid, dash_data_table | ||
|
||
df = px.data.iris() | ||
data = pd.DataFrame( | ||
{ | ||
"Column 1": [1, 2, 3, 4, 5, 6], | ||
"Column 2": ["A", "B", "C", "VeryLongStringInputCell_VeryLongStringInputCell", "D", "E"], | ||
"Column 3": [10.5, 20.1, 30.2, 40.3, 50.4, 60.5], | ||
} | ||
) | ||
|
||
iris_dataset = px.data.iris() | ||
giant_dataset = pd.concat([iris_dataset] * 10000, ignore_index=True) | ||
|
||
|
||
def load_data(): | ||
"""Load data.""" | ||
return data | ||
|
||
|
||
data_manager["my_data"] = load_data | ||
|
||
|
||
@capture("ag_grid") | ||
def custom_dash_ag_grid(data_frame, **kwargs): | ||
"""Custom AgGrid.""" | ||
# print(f"dash_ag_grid -> len: {len(data_frame)}") | ||
return dash_ag_grid(data_frame, **kwargs)() | ||
|
||
|
||
@capture("table") | ||
def custom_dash_data_table(data_frame, **kwargs): | ||
"""Custom DataTable.""" | ||
# print(f"dash_data_table -> len: {len(data_frame)}") | ||
return dash_data_table(data_frame, **kwargs)() | ||
|
||
|
||
@capture("graph") | ||
def custom_px_scatter(data_frame, **kwargs): | ||
"""Custom Scatter plot.""" | ||
# print(f"graph -> len: {len(data_frame)}") | ||
return px.scatter(data_frame, **kwargs) | ||
|
||
data_manager["iris"] = px.data.iris() | ||
|
||
page = vm.Page( | ||
title="Test", | ||
@capture("figure") | ||
def custom_kpi_card(data_frame, **kwargs): | ||
"""Custom KPI card.""" | ||
# print(f"kpi_card -> len: {len(data_frame)}") | ||
return kpi_card(data_frame, **kwargs)() | ||
|
||
|
||
page_grid = vm.Page( | ||
title="Example Page", | ||
layout=vm.Layout( | ||
grid=[[0, 1], [2, 3], [4, 5]], | ||
grid=[ | ||
[0, 1], | ||
[2, 3], | ||
] | ||
), | ||
components=[ | ||
vm.Card( | ||
text=""" | ||
### What is Vizro? | ||
Vizro is a toolkit for creating modular data visualization applications. | ||
""" | ||
vm.AgGrid( | ||
id="outer_ag_grid_id", | ||
figure=custom_dash_ag_grid( | ||
id="inner_ag_grid_id", | ||
data_frame="my_data", | ||
columnDefs=[{"field": col, "checkboxSelection": True, "filter": True} for col in data.columns], | ||
columnSize="autoSize", | ||
defaultColDef={"resizable": True}, | ||
persistence=True, | ||
persistence_type="local", | ||
persisted_props=["selectedRows", "filterModel"], | ||
dashGridOptions={ | ||
"rowSelection": "multiple", | ||
"suppressRowClickSelection": True, | ||
# Turn pagination on to see results: | ||
# "pagination": True, | ||
# "paginationPageSize": 3, | ||
}, | ||
), | ||
actions=[ | ||
vm.Action( | ||
function=filter_interaction(targets=["graph_id"]), | ||
) | ||
], | ||
), | ||
vm.Card( | ||
text=""" | ||
### Github | ||
Checkout Vizro's github page. | ||
""", | ||
href="https://github.com/mckinsey/vizro", | ||
vm.Table( | ||
id="outer_table_id", | ||
figure=custom_dash_data_table( | ||
id="inner_table_id", | ||
data_frame="my_data", | ||
row_selectable="multi", | ||
filter_action="native", | ||
persistence=True, | ||
persistence_type="local", | ||
# Turn pagination on to see results: | ||
# page_action="native", | ||
# page_size=3, | ||
), | ||
), | ||
vm.Card( | ||
text=""" | ||
### Docs | ||
Visit the documentation for codes examples, tutorials and API reference. | ||
""", | ||
href="https://vizro.readthedocs.io/", | ||
vm.Graph( | ||
id="graph_id", | ||
figure=custom_px_scatter(data_frame="my_data", x="Column 1", y="Column 3"), | ||
), | ||
vm.Card( | ||
text=""" | ||
### Nav Link | ||
Click this for page 2. | ||
""", | ||
href="/page2", | ||
vm.Figure( | ||
id="figure_id", | ||
figure=custom_kpi_card(data_frame="my_data", value_column="Column 1"), | ||
), | ||
vm.Graph(id="scatter_chart", figure=px.scatter("iris", x="sepal_length", y="petal_width", color="species")), | ||
vm.Graph(id="hist_chart", figure=px.histogram("iris", x="sepal_width", color="species")), | ||
], | ||
controls=[ | ||
vm.Filter(column="species", selector=vm.Dropdown(value=["ALL"])), | ||
vm.Filter(column="petal_length"), | ||
vm.Filter(column="sepal_width"), | ||
], | ||
controls=[vm.Filter(column="Column 1", selector=vm.RangeSlider(step=1))], | ||
) | ||
|
||
dashboard = vm.Dashboard(pages=[page, page2]) | ||
columnDefs = [{"field": "petal_length"}] | ||
|
||
if __name__ == "__main__": | ||
from vizro import Vizro | ||
dashboard = vm.Dashboard( | ||
pages=[ | ||
vm.Page( | ||
title="Page_1", | ||
components=[vm.Card(text="Dummy page just for testing")], | ||
), | ||
page_grid, | ||
vm.Page( | ||
title="Page_3", | ||
components=[vm.AgGrid(figure=dash_ag_grid(data_frame=giant_dataset, columnDefs=columnDefs))], | ||
), | ||
] | ||
) | ||
|
||
string = dashboard._to_python(extra_imports={"from dash_ag_grid import AgGrid"}) | ||
print(string) # noqa | ||
|
||
Vizro().build(dashboard).run() | ||
if __name__ == "__main__": | ||
Vizro().build(dashboard).run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.