Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Add n_clicks to annotationClickData so that callback is fired when clicking on an annotation multiple times#928

Closed
chriddyp wants to merge 2 commits intodevfrom
annotation-n-clicks
Closed

Add n_clicks to annotationClickData so that callback is fired when clicking on an annotation multiple times#928
chriddyp wants to merge 2 commits intodevfrom
annotation-n-clicks

Conversation

@chriddyp
Copy link
Copy Markdown
Member

Currently dash' verifies that the old props != the new props before firing a callback.

Line: https://github.com/plotly/dash/blame/dev/dash-renderer/src/TreeContainer.js#L126
Commit: plotly/dash@05908b2

This behavior prevents multiple clicks on the same annotation from firing the callback.

Dash's comparison may not be the right behavior, but this PR will at least get around the issue.

@alexcjohnson
Copy link
Copy Markdown
Collaborator

@chriddyp while we investigate a deeper fix, were you able to test out the proposed workaround using circular callbacks plotly/dash#1525 to reset annotationClickData when it's consumed?

@chriddyp
Copy link
Copy Markdown
Member Author

This workaround does indeed work 👍🏼

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import json
app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Graph(id='graph', figure={
        'data': [{'y': [2, 1, 5]}],
        'layout': {
            'annotations': [{
                'text': 'click me',
                'x': 0.5, 'y': 0.5, 'xref': 'paper', 'yref': 'paper',
                'captureevents': True
            }]
        }
    }),
    html.Pre(id='output')
])
@app.callback(
    Output('output', 'children'), 
    Output('graph', 'clickAnnotationData'), 
    Input('graph', 'clickAnnotationData'))
def update_output(c):
    print(c)
    return [json.dumps(c, indent=4), None]
app.run_server(debug=True)

click

@chriddyp chriddyp closed this Feb 19, 2021
@chriddyp chriddyp deleted the annotation-n-clicks branch February 19, 2021 15:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants