Skip to content

[BUG] callback error when accessing layout kwargs, in multipage dash app #3374

Description

@odoublewen

Context

  • result of pip list | grep dash
dash                      3.1.1
dash-bootstrap-components 2.0.3
  • OS: macOS 15.5
  • Browser: both chrome and safari

Describe the bug

To reproduce this bug, I create a multipage site exactly like the one shown in the docs, under the heading "Example: Simple Multi-Page App with Pages". In the pages/analytics.py page, I then added a path_template argument, and changed the layout to use the functional form:

dash.register_page(__name__, path_template="/analytics/<report_id>")

def layout(**kwargs):
    report_id = kwargs["report_id"]
    return html.Div([
        html.H1(f'This is our Analytics page for report {report_id}'),
        html.Div([
            "Select a city: ",
            dcc.RadioItems(
                options=['New York City', 'Montreal', 'San Francisco'],
                value='Montreal',
                id='analytics-input'
            )
        ]),
        html.Br(),
        html.Div(id='analytics-output'),
    ])

But making these small changes results in the following callback error, when running the site in debug mode (see screenshot below):

ID not found in layout

Attempting to connect a callback Input item to component: "analytics-input" but no components with that id exist in the layout. If you are assigning callbacks to components that are generated by other callbacks (and therefore not in the initial layout), you can suppress this exception by setting suppress_callback_exceptions=True. This ID was used in the callback(s) for Output(s): analytics-output.children

Weirdly, the callback error goes away if I change:
report_id = kwargs["report_id"]
to:
report_id = kwargs.get("report_id")

Also, I note that the error message still exists even if I don't do the f-string to format the report_id into the heading (i.e. if the third line of the layout function is just html.H1('This is our Analytics page'),).

Finally, I note that the page still works fine, even with the error message -- but the error message is bothersome and suggests a bug in dash.

Expected behavior

I expect to be able to access kwargs inside of the pages layout function, without creating these callback errors.

Screenshots

Image

Attachment

(I am attaching this zip file, with the 4 simple files:
multi-page-dash-app.zip)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions