import vizro.actions as va
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
tips = px.data.tips().reset_index()
columnDefs = [{"field": col, "hide": col == "index"} for col in tips]
page = vm.Page(
title="Multi-select on a table",
components=[
vm.AgGrid(
title="Select a row to add it to the graph",
figure=dash_ag_grid(tips, columnDefs=columnDefs, dashGridOptions={"rowSelection": {"checkboxes": True}}),
actions=va.set_control(control="index_filter", value="index"),
),
vm.Graph(id="tips_graph", figure=px.histogram(tips, x="tip")),
],
controls=[vm.Filter(id="index_filter", column="index", targets=["tips_graph"], selector=vm.Dropdown(value=[]))],
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()