Hi-
I’m creating a simple 3 graph dashboard with a multi-dropdown from csv using jupyterlab (as recommended); however, I have a couple issues plotting the first graph: first, plotting is a hit or miss. In other words, sometimes it plots locally (slow but it does), sometimes I have to wait 6-10 mins before it loads, and sometimes just doesn’t plot at all. second, I’ve tried a different code (below) to test my project, but it doesn’t launch the local server; instead it prints arrays. Can someone spot what I’m doing wrong?
Thanks!
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import pandas_datareader as pdr
import datetime
import time
from collections import deque
import random
import json
import fix_yahoo_finance as yf
yf.pdr_override()
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
import plotly
import plotly.plotly as py
from plotly.tools import FigureFactory as FF
import plotly.graph_objs as go
To use plotly graphing offline
from plotly.offline import download_plotlyjs
from plotly.offline import init_notebook_mode, plot, iplot
#plotly.tools.set_config_file(sharing=‘private’)
init_notebook_mode(connected=True), plot, iplot
print(plotly.version)
df = pd.read_csv(‘t/FuturesData.csv’)
df.set_index(‘Date’, inplace=True)
index_options = df[‘Indices’].unique
app = dash.Dash()
app.layout = html.Div([
html.H2(‘Futures Risk Transfer’),
html.Div(
[
dcc.Dropdown(
id=“Indices”,
options=[{
‘label’: i,
‘value’: i
}
for i in index_options],
value=‘Indices’),
],
style={‘width’: ‘25%’,
‘display’: ‘inline-block’}),
html.Div(id=‘output-container’),
])
@app.callback(
dash.dependencies.Output(‘output-container’, ‘children’),
[dash.dependencies.Input(‘Indices’, ‘value’)])
def update_graph(Indices):
if Indices == “All Indices”:
df_plot = df.copy()
else:
df_plot = df[df[‘Indices’] == Indices]
df = pd.pivot_table(
df_plot,
index=['Date'],
columns=['Indices'],
values=['Pct_Change'],
aggfunc=sum,
fill_value=0)
trace1 = go.Scatter(x=df[‘Date’], y=df[‘Price’], name=‘Price’)
trace2 = go.Scatter(x=df[‘Date’], y=df[‘High’], name=‘High’)
trace3 = go.Scatter(x=df[‘Date’], y=df[‘Pct_Change’], name=‘Percent Change’)
trace4 = go.Scatter(x=df[‘Date’], y=df[‘CCR’], name=‘Continuously Compounded Rate’)
return {
‘data’: [trace1, trace2, trace3, trace4],
‘layout’:
go.Layout(
xaxis={‘type’: ‘log’, ‘title’: ‘Percent’},
yaxis={‘title’: ‘Date’},
hovermode=‘closest’)
}
if name == ‘main’:
app.run_server(debug=True)