from dash import callback, Input, Output
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.actions import filter_interaction
data = px.data.iris()
@callback(
Output("card_id", "children"),
Input("source_chart", "clickData")
)
def update_card(click_data):
if click_data is None:
return "Click on the graph to apply filter interaction."
return f"Clicked species: '{click_data['points'][0]['customdata'][0]}'"
page = vm.Page(
title="Page Title",
layout=vm.Layout(grid=[
[0, 1],
[-1, 2]
]),
components=[
vm.Graph(
id="source_chart",
figure=px.scatter(data, x="sepal_width", y="sepal_length", color="species", custom_data=["species"]),
actions=[vm.Action(function=filter_interaction(targets=["target_chart"]))]
),
vm.Graph(
id="target_chart",
figure=px.scatter(data, x="sepal_width", y="sepal_length", color="species")),
vm.Card(
id="card_id",
text="Click on the graph to apply filter interaction."
),
],
controls=[
vm.Filter(column="sepal_length")
]
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()