Hello, I’m trying to run (locally) a sample code for a project of a live-graph but when I do it it loads the Dash tab but I receive an error message every second saying “Callback error updating live-graph.figure”. When I deploy the message it says: “IndexError: deque index out of range”
According to it, the error is on line 30: X.append(X[X[-1] + 1])
I don’t know if it’s actually that line or the parameters of the function, I’m new using this, I’d be glad if anyone can help me.
The code is here, I’m using Jupyter. Thanks.
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
import plotly
import plotly.graph_objs as go # for making plot.ly graph objects
from dash.dependencies import Input, Output
from collections import deque
import random
X = deque(maxlen = 20)
X.append(1)
Y = deque(maxlen = 20)
Y.append(1)
app = dash.Dash(__name__)
# Layout
app.layout = html.Div([
dcc.Graph(id = 'live-graph', animate = True),
dcc.Interval(id = 'graph-update', interval = 1000)
])
# Callbacks
@app.callback(Output('live-graph', 'figure'),
[Input('graph-update', 'n_intervals')])
def update_graph(input_data):
X.append(X[X[-1] + 1])
Y.append(Y[Y[-1] + (Y[-1]*random.uniform[-0.1, 0.1])])
data = gp.Scatter(
x = list(X),
y = list(Y),
name = 'Temperature',
mode = 'lines + markers'
)
return {'data':[data], 'layout':go.Layout(xaxis = dict(range = [min(X), max(X)]),
yaxis = dict(range = [min(Y), max(Y)])
)}
if __name__ == "__main__":
app.run_server(debug = True)