Hello! I am trying to make a live updating heatmap using Jupyter Dash. My main requirement is that dash works equally well with both small dataframes and large ones (several million elements).
So I decided that the application should be as simple as possible. An example of my code implementation is below:
# Build App
app = JupyterDash(__name__)
app.layout = html.Div(
[
dcc.Graph(id="heatmap", animate=True),
dcc.Interval(id="interval-component", interval=1*1000),
],
)
@app.callback(Output('heatmap', 'figure'),
Input("interval-component", "n_intervals"))
def doUpdate(i):
traces = list()
traces.append(go.Heatmap(z=data.get_result_for_plot(),
colorscale='RdBu'))
# data.get_result_for_plot() just returns new version of np array
return {'data': traces}
However the code doesnโt work correctly and first of all the following error pops up: Callback error updating heatmap.figure
, and then another one: Error from API call: _reload-hash
. On top of that the jupyter kernel dies.
So I have several questions:
- what did I do wrong in my implementation?
- Is there any way to improve this code?
For example, I would like to create a figure outside of doUpdate() function and update only z coordinate, to reduce load.
I would be very glad to get advice on these issues. Thanks!