"""Dev app to try things out."""
import pandas as pd
from dash import callback, Input, Output, no_update
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
from vizro.models.types import capture
iris = px.data.iris()
ag_grid_fake_data = pd.DataFrame(
{
"name": ["John", "Jane", "Joe", "Jake"],
"age": [25, 30, 35, 40],
"graph_type": ["scatter", "box", "scatter", "box"],
"city": ["New York", "Los Angeles", "Chicago", "Houston"],
}
)
@capture("graph")
def custom_graph(data_frame, graph_type, **kwargs):
if graph_type == "scatter":
return px.scatter(data_frame, **kwargs)
elif graph_type == "box":
return px.box(data_frame, **kwargs)
page = vm.Page(
title="My Page Title",
components=[
vm.AgGrid(
id="ag_grid_id",
title="My Grid",
header="⤵ Click on a \"Graph_type\" column cell to select the chart type below.",
figure=dash_ag_grid(
id="underlying_ag_grid_id",
data_frame=ag_grid_fake_data
),
),
vm.Graph(
id="graph_id",
title="My Graph",
figure=custom_graph(
data_frame=iris,
graph_type="scatter",
x="sepal_width",
y="sepal_length",
color="species"
)
),
],
controls=[
vm.Filter(column="species"),
vm.Parameter(
targets=["graph_id.graph_type"],
selector=vm.RadioItems(
id="graph_type_parameter_id",
options=["scatter", "box"],
value="scatter",
)
)
]
)
@callback(
Output("graph_type_parameter_id", "value"),
Input("underlying_ag_grid_id", "cellClicked"),
)
def update_parameter(ag_grid_cell_clicked):
if not ag_grid_cell_clicked:
return no_update
return ag_grid_cell_clicked["value"]
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run(debug=False)