In a Dash app, I would like to toggle the values of a boolean array when markers in a scatterplot are clicked. If I click the same marker twice in a row, I would like to toggle that value twice, but the second click is not registered. I can only click on some other marker.
Here is a minimal working example:
from dash import Dash, html, dcc
from dash.dependencies import Input, Output
from plotly import graph_objects as go
bools = [False, False, False]
app = Dash(__name__)
fig = go.Figure(go.Scatter(x=[0, 1, 2], y = [2, 1, 2]))
graph = dcc.Graph(id = 'graph', figure = fig)
app.layout = html.Div(graph)
@app.callback(
Output('graph', 'figure'),
Input('graph', 'clickData')
)
def toggle(clickData):
global bools
n_marker = clickData['points'][0]['pointNumber']
bools[n_marker] = not bools[n_marker]
print(bools)
app.run_server(debug = True)
This seems related to this old question using plotly in R, but I wasn't able to figure out how to use the answers there in python + dash.
