Dash 有趣的股票小APP
2017-10-31 本文已影响37人
DTAnalystLi
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import tushare as ts
from datetime import datetime as dt
app = dash.Dash()
app.layout = html.Div([
html.H1('小李的股票查询小平台'),
dcc.Dropdown(
id='my-dropdown',
options=[
{'label': '平安银行', 'value': '000001'},
{'label': '临港集团', 'value': '600848'},
{'label': '万年青', 'value': '000789'}
],
value='COKE'
),
dcc.Graph(id='my-graph')
])
@app.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
df = ts.get_hist_data(selected_dropdown_value, start='2017-01-05', end='2017-10-01')
# df = ts.get_hist_data('000001', start='2017-01-05', end='2017-10-01')
# df = web.DataReader(
# selected_dropdown_value, data_source='google',
# start=dt(2017, 1, 1), end=dt.now())
return {
'data': [{
'x': df.index,
'y': df.close
}]
}
if __name__ == '__main__':
app.run_server()