Skip to content

Instantly share code, notes, and snippets.

@okomarov
Last active February 21, 2019 20:00
Show Gist options
  • Save okomarov/f07a7e67d321f03487c043f6e00453c0 to your computer and use it in GitHub Desktop.
Save okomarov/f07a7e67d321f03487c043f6e00453c0 to your computer and use it in GitHub Desktop.
layout.py
from datetime import datetime as dt
import pandas_datareader as pdr
from dash.dependencies import Input
from dash.dependencies import Output
def register_callbacks(dashapp):
@dashapp.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
df = pdr.get_data_yahoo(selected_dropdown_value, start=dt(2017, 1, 1), end=dt.now())
return {
'data': [{
'x': df.index,
'y': df.Close
}],
'layout': {'margin': {'l': 40, 'r': 0, 't': 20, 'b': 30}}
}
import dash_core_components as dcc
import dash_html_components as html
layout = html.Div([
html.H1('Stock Tickers'),
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')
], style={'width': '500'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment