Black Lives Matter. Please consider donating to Black Girls Code today.

[Help] Once set the graph return None, the graph won't update anymore even when get new data

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&#32’,
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


Apparently, its a bug…
chris asked for a fully functional code… would be wonderful if you could help with that!

I will try shortening my code, while mine now is using some api to get data updated. For most other live-updating dash apps are working well, except this.

Meet the similar issue.
The input callback of html.Button are failed to update(No update in 'n_clicks" counter).
Here is the demo code.

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import datetime
import plotly.figure_factory as ff

app = dash.Dash()
app.config.suppress_callback_exceptions = True
return_figure_result = True

app.layout = html.Div([
    html.H3('Refresh text of div'),
    dcc.Graph(
        id="Graph"
    ),
    html.Div(
        children="Hello",
        id='MainPageOutput'
    ),
    html.Button(
        children="Fire",
        id='MainPageButton',
    )
])


@app.callback(
    Output('MainPageOutput', 'children'),
    [Input('MainPageButton', 'n_clicks')]
)
def update_value(n_clicks):
    print "update_value {}".format(n_clicks)
    return 'MainPage Now {} {}'.format(
        n_clicks,
        datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    )


@app.callback(
    Output('Graph', 'figure'),
    [Input('MainPageButton', 'n_clicks')]
)
def update_graph(n_clicks):
    results = [[1,2,2,3,3,2,4,2342,42], [223,23,2,32,42,42,4,2,42,42,4,24,2,234]]
    hist_data = results
    group_labels = ["A Group", "B Group"]

    figure = ff.create_distplot(hist_data, group_labels, show_hist=False)
    figure["layout"].update(title=str(n_clicks))
    print "update_graph {}".format(n_clicks)

    if return_figure_result:
        return figure

if __name__ == '__main__':
    debug = True
    host = '0.0.0.0'
    app.run_server(debug=debug, host=host)

Set variable “return_figure_result” as “False” which can reproduce issue that no update in counter and page.

Any update here ?
This is not the big issue actually but i want to get the confirmation is it the bugs ?