✊🏿 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


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.Button('Click', id='btn')

    Output('output', 'children'),
    [Input('btn', 'n_clicks'),]
def cb(_):

if __name__ == '__main__':

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('    ', ''))
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