Enabling clickData for part of a go.Figure

Hi,
I am trying to create interactive graphs for my dash app by referring to https://dash.plot.ly/interactive-graphing. . I want to create some interactions based on data points that are clicked on the scatter plot.

I have a figure that has is composed of two scatter plots. I have enabled clicking by choosing the clickmode as event+select in the layout as shown in the code below. How can I enable clicking for one scatter plot and disable clicking for the other scatter plot?

data = [go.Scatter(x=df_pca['1'],
                               y=df_pca['2'],
                               mode='markers',
                               name='unlabeled data'),
                    go.Scatter(x=df_train_pca['1'],
                               y=df_train_pca['2'],
                               mode='markers',
                               name='training data')
                    ]
layout = go.Layout(clickmode='event+select')
fig = go.Figure(data, layout)

Good question! I’m not aware of any way to do that within the plot itself, but one option is to selectively abort the callback. Look at clickData['points'][0]['curveNumber'], and if it’s the wrong trace raise dash.exceptions.PreventUpdate (or alternatively, return dash.no_update).

1 Like