This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
/
dash-animate-range.py
69 lines (60 loc) · 1.83 KB
/
dash-animate-range.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
import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
app = dash.Dash()
value_range = [-5, 5]
app.layout = html.Div([
html.Div([
html.Div(dcc.Graph(animate=True, id='graph-1'), className="six columns"),
html.Div(dcc.Graph(animate=True, id='graph-2'), className="six columns")
], className="row"),
dcc.RangeSlider(
id='slider',
min=value_range[0],
max=value_range[1],
step=1,
value=[-2, 2],
marks={i: i for i in range(value_range[0], value_range[1]+1)}
)
], className="container")
trace = {
'mode': 'markers',
'marker': {
'size': 12,
'opacity': 0.5,
'line': {
'width': 0.5,
'color': 'white'
}
}
}
@app.callback(
dash.dependencies.Output('graph-1', 'figure'),
[dash.dependencies.Input('slider', 'value')])
def update_graph_1(value):
x = np.random.rand(50) * (value[1] - value[0]) + value[0]
y = np.random.rand(50) * (value[1] - value[0]) + value[0]
return {
'data': [dict({'x': x, 'y': y}, **trace)],
'layout': {
'xaxis': {'range': [np.min(x), np.max(x)]},
'yaxis': {'range': [np.min(y), np.max(y)]}
}
}
@app.callback(
dash.dependencies.Output('graph-2', 'figure'),
[dash.dependencies.Input('slider', 'value')])
def update_graph_1(value):
x = np.random.rand(50) * (value[1] - value[0]) + value[0]
y = np.random.rand(50) * (value[1] - value[0]) + value[0]
return {
'data': [dict({'x': x, 'y': y}, **trace)],
'layout': {
'xaxis': {'range': value_range},
'yaxis': {'range': value_range}
}
}
app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
if __name__ == '__main__':
app.run_server(debug=True)