✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚾️ It's finally Baseball season! Root for the home team... & Register for our Sports Analytics Webinar!

NonExistantIdException when invalid layout

dash==0.29.0rc6
dash-core-components==1.0.0rc1
dash-html-components==0.14.0rc2
dash-renderer==0.15.0rc2

The code below raises a dash.exceptions.NonExistantIdException when executed. It turns out that the exception is due to an invalid layout (Div([[...]]) rather than Div([...])), what we can figure out by opening the page in the browser. I think the error is not clear though because it doesn’t point to the problem (only to one of its consequences).

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State


app = dash.Dash(__name__)
app.layout = html.Div([[  # Invalid children
    html.Div(id='output'),
    html.Button('Click', id='btn')
]])


@app.callback(
    Output('output', 'children'),
    [Input('btn', 'n_clicks'),]
)
def cb(_):
    pass


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

When run, it gives:

Traceback (most recent call last):
  File "layout_error.py", line 16, in <module>
    [Input('btn', 'n_clicks'),]
  File "/home/vincent/.local/share/virtualenvs/dash_forms/lib/python3.7/site-packages/dash-0.29.0rc6-py3.7.egg/dash/dash.py", line 818, in callback
    self._validate_callback_definition(output, inputs, state, events)
  File "/home/vincent/.local/share/virtualenvs/dash_forms/lib/python3.7/site-packages/dash-0.29.0rc6-py3.7.egg/dash/dash.py", line 622, in _validate_callback_definition
    ).replace('    ', ''))
dash.exceptions.NonExistantIdException: 
Attempting to assign a callback to the
component with the id "output" but no
components with id "output" exist in the
app's layout.


Here is a list of IDs in layout:
[]


If you are assigning callbacks to components
that are generated by other callbacks
(and therefore not in the initial layout), then
you can suppress this exception by setting
`app.config['suppress_callback_exceptions']=True`.

Thanks!