forked from radovankavicky/dash-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_callbacks.py
More file actions
96 lines (71 loc) · 2.63 KB
/
Copy pathgraph_callbacks.py
File metadata and controls
96 lines (71 loc) · 2.63 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import dash_html_components as html
import dash_core_components as dcc
from tutorial import styles
from tutorial import tools
print('Loading examples')
examples = [
tools.load_example(s) for s in [
'tutorial/examples/graph_callbacks_simple.py',
'tutorial/examples/graph_callbacks_crossfiltering.py',
'tutorial/examples/graph_callbacks_same_graph.py'
]
]
layout = [dcc.Markdown('''
# Graph Callbacks
Dash renders graphs using the interactive
[plotly.js](https://github.com/plotly/plotly.js) graphing library.
Plotly.js graphs are natively interactive.
- Hover over points to see their values
- Click and drag on the graph to zoom into regions
- Double click to zoom out
- Shift + Click + Drag to pan regions
- Select points using the lasso or the rectangle in the graph bar
With dash, these events update the `Graph` component's
`clickData`, `hoverData`, and `selectedData` values.
By setting those properties as `Input` properties, you can
update your Dash application in response to these events.
'''),
dcc.SyntaxHighlighter(examples[0][0], customStyle=styles.code_container),
html.Div(examples[0][1], className="example-container")
]
layout.extend([
dcc.Markdown('''
***
## Crossfiltering Between Graphs
One of the really powerful things that you can do with these types of
variables is cross filtering between charts, allowing you to interact
with multiple dimensions of data across multiple views at once.
Here's a simple example.
In this example, we use the `customdata` property to add extra
metadata for the points that we've hovered over or selected.
'''),
dcc.SyntaxHighlighter(examples[1][0], customStyle=styles.code_container),
html.Div(
examples[1][1],
className="example-container",
style=dict({'paddingBottom': '30px'})
)
])
layout.extend([
dcc.Markdown('''
This graph is highly interactive. Hovering over values will trigger our
callbacks and highlight the associated point (country) in the other graph.
The exact same filtering operation occurs if you select multiple points
by clicking and dragging on the plot with the lasso. The slider ties it
together by filtering the data by selected year.
***
It's also possible to update the same the graph in response to these events.
Here's another take on this dataset. Hovering over a value will replot the
chart with that country's historical trajectory.
'''),
dcc.SyntaxHighlighter(
examples[2][0],
language='python',
customStyle=styles.code_container
),
html.Div(
examples[2][1],
className="example-container",
style=dict(paddingBottom='30px')
)
])