📣 Dash v1.11.0 Release - Introducing Pattern-Matching Callbacks

This is amazing news. Thank you.

In addition, I have one question about app.config.suppress_callback_exceptions.

So I have a multi-page application, I have a callback function1 to generate a barchart with id b1. Then I have a callback function2 that use id b1 as input to get its clickData value. With version 1.11.0, I got the error

'A nonexistent object was used in an Input of a Dash callback. The id of this object is b1 ’

I understood that i was calling the b1 in my callback before the component is defined on initial layout. So I used app.config.suppress_callback_exceptions = True. This is working for the previous version 1.10.0 but not the most recent version. Did we have any changes on this functionality? How should i suppress the exception with 1.11.0?

I have modified the code for pattern-matching callbacks to reproduce my error

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

app = dash.Dash(__name__, suppress_callback_exceptions=True)

app.layout = html.Div([
    html.Div(id='content'),
    dcc.Location(id='url', refresh=False)
])


def render_layout():
    return html.Div([
        html.Button("Add Filter", id="add-filter", n_clicks=0),
        html.Div(id='dropdown-container', children=[]),
        html.Div(id='dropdown-container-output')
    ])


@app.callback(dash.dependencies.Output('content', 'children'),

              [dash.dependencies.Input('url', 'pathname')],
              [dash.dependencies.State('url', 'href')])
def display_content(url, href):
    if url:
        return render_layout()


@app.callback(
    Output('dropdown-container', 'children'),
    [Input('add-filter', 'n_clicks')],
    [State('dropdown-container', 'children')])
def display_dropdowns(n_clicks, children):
    new_dropdown = dcc.Dropdown(
        id='filter-dropdown',
        options=[{'label': i, 'value': i} for i in ['NYC', 'MTL', 'LA', 'TOKYO']]
    )
    children.append(new_dropdown)
    return children


@app.callback(
    Output('dropdown-container-output', 'children'),
    [Input('filter-dropdown', 'value')]
)
def display_output(values):
    return html.Div([
        html.Div('Dropdown {} = {}'.format(i + 1, value))
        for (i, value) in enumerate(values)
    ])


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

Here is the output
image

Thanks for looking into this.

1 Like