-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample3.py
More file actions
49 lines (43 loc) · 994 Bytes
/
example3.py
File metadata and controls
49 lines (43 loc) · 994 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from dash import dcc, html, Dash
from dash.dependencies import Input, Output
app = Dash(__name__)
app.layout = html.Div(children = [
html.H1("more interesting callbacks!"),
dcc.Dropdown(
id="choice",
options=[
{"label": "Apple", "value": "AAPL"},
{"label": "Google", "value": "GOOG"},
{"label": "Microsoft", "value": "MSFT"},
],
value="GOOG"
),
dcc.Graph(
id="stock-graph",
figure={
"data": [],
"layout": {
"title": "Stock prices"
}
}
)
])
stocks = {
"AAPL": [1, 1.4, 2],
"GOOG": [4, 1, 2],
"MSFT": [12, 2, 1]
}
@app.callback(
Output(component_id="stock-graph",component_property="figure"),
[Input(component_id="choice", component_property="value")]
)
def change_h2_on_input_change(value):
return {
"data": [
{'x': ["Jan", "Feb", "Mar"], 'y': stocks[value], 'type': 'bar', 'name': value},
],
"layout": {
"title": "Stock prices"
}
}
app.run_server()