Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬 Register for the Oct 27 webinar.

Suppress_callback_exceptions for clickData input

Reading the community board, suppress_callback_exceptions seems to have some problems. See here or here.

How do you use pattern-matching as a work around for clickData? I want to use clickData from a Choropleth map, which itself is created dynamically.

The problem is that adding app.config.suppress_callback_exceptions = True still triggers an error:

Attempting to connect a callback Input item to component:
  "choro"
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):
  details.children

Here is the original code that throws the error.

app.layout = html.Div([
    html.Div([
        dcc.Dropdown(id='country_dd', options=...)
        dcc.Dropdown(id='level_dd', options=...)
        dcc.RadioItems(id='radio_in', options=...)]),
    html.Div(
        dcc.Loading(id='load_choro',
                    children=[html.Div(id='choromap')],
                    type='graph')),
    html.Div(id='details')
])

# details information after map click
@app.callback(Output('details', 'children'),
              [Input('choro', 'clickData')])
def mapclick(value):
    return json.dumps(value, indent=2)

# choropleth map
@app.callback(Output('load_choro', 'children'),
              [Input('country_dd', 'value'),
               Input('level_dd', 'value'),
               Input('radio_in', 'value')])
def radiocall(country, level, analysis):
    ...
    figure = ...
    return html.Div(dcc.Graph(id='choro', figure=figure)

Unsuccessful fix with pattern-matching. It threw NameError: name 'clickData' is not defined.

# AMENDED details information after map click
@app.callback(Output('details', 'children'),
              [Input({'type': 'choro', 'index': ALL}, 'clickData')]) # Inclusion of pattern-matching
def mapclick(value):
    return json.dumps(value, indent=2)

# AMENDED return statement
def radiocall(country, level, analysis):
    ...
    figure = ...
    return html.Div(dcc.Graph(id={'type': 'choro', 'index': clickData}, figure=figure))  # Inclusion of pattern-matching