This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathdash-scattergl-select.py
106 lines (88 loc) · 2.83 KB
/
dash-scattergl-select.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
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
97
98
99
100
101
102
103
104
105
106
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import pandas as pd
app = dash.Dash()
df = pd.DataFrame({
'Column {}'.format(i): np.random.rand(50) + i*10
for i in range(6)})
app.layout = html.Div([
html.Div(
dcc.Graph(
id='g1',
selectedData={'points': [], 'range': None}
), className="four columns"
),
html.Div(
dcc.Graph(
id='g2',
selectedData={'points': [], 'range': None}
), className="four columns"),
html.Div(
dcc.Graph(
id='g3',
selectedData={'points': [], 'range': None}
), className="four columns")
], className="row")
def highlight(x, y):
def callback(*selectedDatas):
index = df.index
for i, hover_data in enumerate(selectedDatas):
selected_index = [
p['customdata'] for p in selectedDatas[i]['points']
# the first trace that includes all the data
if p['curveNumber'] == 0
]
if len(selected_index) > 0:
index = np.intersect1d(index, selected_index)
dff = df.iloc[index, :]
figure = {
'data': [
dict({
'x': df[x], 'y': df[y], 'text': df.index,
'customdata': df.index,
'mode':'markers',
'type': 'scattergl', 'opacity': 0.1
}),
dict({
'x': dff[x], 'y': dff[y], 'text': dff.index,
'mode':'markers',
'type': 'scattergl', 'textposition': 'top',
}),
],
'layout': {
'margin': {'l': 20, 'r': 0, 'b': 20, 't': 5},
'dragmode': 'select',
'hovermode': 'closest',
'showlegend': False
}
}
return figure
return callback
app.css.append_css({
"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
# app.callback is a decorator which means that it takes a function
# as its argument.
# highlight is a function "generator": it's a function that returns function
app.callback(
Output('g1', 'figure'),
[Input('g1', 'selectedData'),
Input('g2', 'selectedData'),
Input('g3', 'selectedData')]
)(highlight('Column 0', 'Column 1'))
app.callback(
Output('g2', 'figure'),
[Input('g2', 'selectedData'),
Input('g1', 'selectedData'),
Input('g3', 'selectedData')]
)(highlight('Column 2', 'Column 3'))
app.callback(
Output('g3', 'figure'),
[Input('g3', 'selectedData'),
Input('g1', 'selectedData'),
Input('g2', 'selectedData')]
)(highlight('Column 4', 'Column 5'))
if __name__ == '__main__':
app.run_server(debug=True)