plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.53k stars 2.07k forks source link

dcc.Graph rendering goes into infinite error loop when None is returned for Figure #2992

Open reggied opened 2 months ago

reggied commented 2 months ago

Describe your context Please provide us your environment, so we can easily reproduce the issue.

  dash                           2.18.0
  dash-core-components           2.0.0
  dash-html-components           2.0.0
  dash-table                     5.0.0

Describe the bug

When running the below script (which has a bug: graph_selections returns None instead of a Figure) with python3, and displaying in the Chrome browser, the browser tab seems to lock up. If the developer tools are open, one can see the error count rapidly rising with the errors in the screenshot below being repeated over and over again in a tight loop.

from dash import Dash, html, dcc, callback, Output, Input

app = Dash()
app.layout = html.Div([
    html.Button('RUN', id='run-btn', n_clicks=0),
    dcc.Graph(id='graph-container')
])

@callback(
    Output('graph-container', 'figure'),
    Input('run-btn', 'n_clicks'),
)
def graph_selections(n_clicks):
    print(n_clicks)

if __name__ == "__main__":
    app.run(port=8050, host='0.0.0.0', debug=True)

Expected behavior

An error message in the browser, describing the bad return from the callback..

Screenshots

Screenshot 2024-09-09 at 12 28 28