-
Notifications
You must be signed in to change notification settings - Fork 1
/
09_dash_03.py
57 lines (54 loc) · 1.74 KB
/
09_dash_03.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
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas_datareader.data as web # requires v0.6.0 or later
from datetime import datetime
app = dash.Dash()
app.layout = html.Div([
html.H1('Stock Ticker Dashboard'),
html.Div([
html.H3('Enter a stock symbol:', style={'paddingRight':'30px'}),
dcc.Input(
id='my_ticker_symbol',
value='TSLA', # sets a default value
style={'fontSize':24, 'width':75}
)
], style={'display':'inline-block', 'verticalAlign':'top'}),
html.Div([
html.H3('Select start and end dates:'),
dcc.DatePickerRange(
id='my_date_picker',
min_date_allowed = datetime(2015, 1, 1),
max_date_allowed = datetime.today(),
start_date = datetime(2018, 1, 1),
end_date = datetime.today()
)
], style={'display':'inline-block'}),
dcc.Graph(
id='my_graph',
figure={
'data': [
{'x': [1,2], 'y': [3,1]}
]
}
)
])
@app.callback(
Output('my_graph', 'figure'),
[Input('my_ticker_symbol', 'value'),
Input('my_date_picker', 'start_date'),
Input('my_date_picker', 'end_date')])
def update_graph(stock_ticker, start_date, end_date):
start = datetime.strptime(start_date[:10], '%Y-%m-%d')
end = datetime.strptime(end_date[:10], '%Y-%m-%d')
df = web.DataReader(stock_ticker,'iex',start,end)
fig = {
'data': [
{'x': df.index, 'y': df.close}
],
'layout': {'title':stock_ticker}
}
return fig
if __name__ == '__main__':
app.run_server()