Callback for repeated data click

Hey @bhowey

You are right, the clickData does not get reset automatically. So if you click twice on the same point, the callback gets triggered only once. You have to manually reset the clickData:

@app.callback(
    Output('map', 'figure'),
    Output('map', 'clickData'),
    [Input('map', 'clickData'),
     Input('dummy-button', 'n_clicks')],
    [State('df-store', 'data')]
)
def update_marker_color(clickData, dummy_button_n_clicks, df_json):
    df_new = pd.read_json(df_json)
    if clickData:
        pointIndex = clickData['points'][0]['pointIndex']
        # Toggle the 'Inspected' value
        df_new.at[pointIndex, 'Inspected'] = not df_new.at[pointIndex, 'Inspected']
    else:
        print('click is none')

    # Update marker color based on 'Inspected' column
    fig = px.scatter_mapbox(df_new, lat="Latitude", lon="Longitude", hover_name="GinNumber", color="Inspected", zoom=3, height=300, hover_data=['GinNumber','DateIncident','IncidentLocation','CasualtyName','Latitude','Longitude'])
    fig.update_layout(mapbox_style="open-street-map")
    fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
    fig['layout']['uirevision'] = 'some-constant'
    return fig, {}

This does not solve the other issue you have, however.

1 Like