Py.Cafe

maxi.schulz/

linkedin-callback-example

Example showcasing pure Dash with Vizro

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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()