Hi all,
It’s really weird that when I set the return based on some condition like if the data==, then return None to one graph. Then even when I get new data != and return traces, the graph won’t update anymore. And it not only interfere one graph, it will stop all the graph in the same dash app to update the graphs.
Sample code:
Here like we set up two graphs in one dash app. One is return graph only when meet the condition. One is always updating graph. Both updated by interval. Once I remove the condition and make it always updating, the dash app works well.
What I want is to display the graph only when meet the condition otherwise just make the graph empty (not to show the old graphs). So my question is what is the reason here to cause the issue? And what could be the best way to deal with my requirement?
Thanks!
Besides, when check the develop mode in browser, I can see the data is always updating correctly, i.e. the feed (input/output) to signal is working and the data inside is also updating. But none of the dash-graphs is updating anymore when the fig1 return None.
Blockquote
@app.callback(Output(‘fig’, ‘figure’), [Input(‘signal’, ‘children’)], , [Event(‘interval-component’, ‘interval’)])
def update_figure(data):
data = json.loads(data)
h = np.array(data[‘h’])
f = np.array(data[‘f’])
t = np.array(data[‘t’])
if h:
traces = [
go.Heatmap(
z=h[1:, :10],
x=t[1:],
y=f[:10],
colorscale=‘Viridis’,
)
]
layout = go.Layout(
title=‘Waterfall Spectrum ’,
xaxis={‘title’: ‘Time [sec]’},
yaxis={‘title’: ‘Frequency [Hz]’},
hovermode=‘closest’
)
return {
‘data’: traces,
‘layout’: layout,
}
else:
return None
@app.callback(Output(‘fig2’, ‘figure’), [Input(‘signal’, ‘children’)], , [Event(‘interval-component’, ‘interval’)])
def update_figure2(data):
data = json.loads(data)
traces =
traces.append(go.Scatter(
x=len(data[‘1’]),
y=data[‘1’],
text=“p”,
mode=‘line’,
# opacity=0.7,
name=“p”,
))
print(“updating fig2”, flush=True)
return {
‘data’: traces,
‘layout’: go.Layout(
title='Waveform ’ ,
xaxis={‘title’: ‘Index’},
yaxis={‘title’: 'W '},
# margin={‘l’: 40, ‘b’: 40, ‘t’: 10, ‘r’: 10},
legend={‘x’: 0, ‘y’: 1},
hovermode=‘closest’
)
}
Blockquote