forked from plotly/dash-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdash-add-graphs-dynamically.py
More file actions
35 lines (29 loc) · 926 Bytes
/
dash-add-graphs-dynamically.py
File metadata and controls
35 lines (29 loc) · 926 Bytes
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
import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash()
app.layout = html.Div([
html.Button(id='button', n_clicks=0, children='Add graph'),
html.Div(id='container'),
html.Div(dcc.Graph(id='empty', figure={'data': []}), style={'display': 'none'})
])
@app.callback(Output('container', 'children'), [Input('button', 'n_clicks')])
def display_graphs(n_clicks):
graphs = []
for i in range(n_clicks):
graphs.append(dcc.Graph(
id='graph-{}'.format(i),
figure={
'data': [{
'x': [1, 2, 3],
'y': [3, 1, 2]
}],
'layout': {
'title': 'Graph {}'.format(i)
}
}
))
return html.Div(graphs)
if __name__ == '__main__':
app.run_server(debug=True)