Good day guys
I am having a challenge of generating subplots using cufflinks. Using the Cufflinks tutorial to generate the function am using which I wrote as follows
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
import pandas as pd
import cufflinks as cf
from plotly.offline import iplot
import plotly.tools as tls
cf.go_offline()
def subplots(df,x):
hover_text = df.apply(lambda r: '<br>'.join(['{}: {}'.format(c, r[c])
for c in df.columns]), axis=1)
fig = tls.make_subplots(rows=2, cols=1, shared_xaxes=True)
fig.append_trace({'x': df.index, 'y': df.Close, 'type': 'scatter',
'name': x, 'text': hover_text}, 1, 1)
fig.append_trace({'x': df.index, 'y': df.Volume, 'type': 'bar',
'name': 'Volume', 'text': hover_text}, 2, 1)
figure = iplot(fig)
return figure
app = dash.Dash()
app.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')
])
@app.callback(Output('my-graph', 'figure'), [Input('dropdown', 'value')])
def update_graph(selected_dropdown_value):
df = web.DataReader(
selected_dropdown_value, data_source='google',
start=dt(2017, 1, 1), end=dt.now())
return subplots(df,selected_dropdown_value)
if __name__ == '__main__':
app.run_server()
But am returning a blank canvas for the plot. What could I have done wrongly there.