-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashStock.py
38 lines (34 loc) · 1002 Bytes
/
dashStock.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
# -*- coding: UTF-8 -*-
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from pandas_datareader import data as web
from datetime import datetime as dt
app = dash.Dash()
app.layout = html.Div([
html.H1('Yahoo Stock Ticker'),
dcc.Dropdown(
id='my-dropdown',
options=[
{'label': 'Coke', 'value': 'COKE'},
{'label': 'Tesla', 'value': 'TSLA'},
{'label': 'Apple', 'value': 'AAPL'},
],
value='COKE'
),
dcc.Graph(id='my-graph')
])
@app.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
df = web.DataReader(
selected_dropdown_value, data_source='yahoo',
start=dt(2018, 1, 1), end=dt.now())
return {
'data': [{
'x': df.index,
'y': df.Close
}]
}
if __name__ == '__main__':
app.run_server(debug=True, port=8090)