-
Notifications
You must be signed in to change notification settings - Fork 29
/
dashapp.py
61 lines (52 loc) · 1.78 KB
/
dashapp.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
import dash
from dash.dependencies import Input, Output
from dash import dcc, html
import flask
import pandas as pd
import os
def create_dash_app(requests_pathname_prefix: str = None) -> dash.Dash:
"""
Sample Dash application from Plotly: https://github.com/plotly/dash-hello-world/blob/master/app.py
"""
server = flask.Flask(__name__)
server.secret_key = os.environ.get('secret_key', 'secret')
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/hello-world-stock.csv')
app = dash.Dash(__name__, server=server, requests_pathname_prefix=requests_pathname_prefix)
app.scripts.config.serve_locally = False
dcc._js_dist[0]['external_url'] = 'https://cdn.plot.ly/plotly-basic-latest.min.js'
app.layout = html.Div([
html.H1('Stock Tickers'),
dcc.Dropdown(
id='my-dropdown',
options=[
{'label': 'Tesla', 'value': 'TSLA'},
{'label': 'Apple', 'value': 'AAPL'},
{'label': 'Coke', 'value': 'COKE'}
],
value='TSLA'
),
dcc.Graph(id='my-graph')
], className="container")
@app.callback(Output('my-graph', 'figure'),
[Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
dff = df[df['Stock'] == selected_dropdown_value]
return {
'data': [{
'x': dff.Date,
'y': dff.Close,
'line': {
'width': 3,
'shape': 'spline'
}
}],
'layout': {
'margin': {
'l': 30,
'r': 20,
'b': 30,
't': 20
}
}
}
return app