Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ClickData callback not triggering when clicking the same segment of pie chart #1300

Closed
wompo opened this issue Jun 12, 2020 · 10 comments
Closed

Comments

@wompo
Copy link

wompo commented Jun 12, 2020

Describe your context
Please provide us your environment so we can easily reproduce the issue.

dash                 1.12.0
dash-core-components 1.10.0
dash-html-components 1.0.3
dash-renderer        1.4.1
  • if frontend related, tell us your Browser, Version and OS

    • OS: Windows 10
    • Browser: chrome
    • Version: 83.0.4103.97 (Official Build) (64-bit)

Describe the bug

When using pie chart clickData as an input for a callback, it does not trigger when clicking the same segment twice (or multiple times) in a row.

Expected behavior

I would expect the callback to trigger again with the same clickData.

Simple app

A simple app to help reproduce the bug.

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import json

labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [4500, 2500, 1053, 500]

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Graph(
        id='pie',
        figure={
            'data': [{
                'values': values,
                'labels': labels,
                'type': 'pie'
            }]
        }
    ),
    html.Pre(id='clickDataDisplay')
])

@app.callback(
    Output('clickDataDisplay', 'children'),
    [Input('pie', 'clickData')]
)
def display_click_data(clickData):
    print("Processing click data.")
    return json.dumps(clickData, indent=2)

if __name__ == '__main__':
    app.run_server(debug=True)
@codebicycle
Copy link

It affects bar charts as well as pie charts.
Actually, it affects all charts supported by dcc.Graph, starting with Dash version 1.11.0.

From Dash v1.11.0 release notes:

"A user interaction which returns the same property value as was previously present will not trigger the component to re-render, nor trigger callbacks using that property as an input."

Are there any workarounds to trigger a callback when clicking on the same section of a graph again?

@ValeriyaGriffiths
Copy link

ValeriyaGriffiths commented Nov 17, 2020

I've got the same problem in dash 1.13.4. Any updates regarding a fix or a workaround would be very much appreciated.

@panizoeva
Copy link

panizoeva commented Jan 16, 2021

Same issue here in environment:

dash                      1.17.0       
dash-core-components      1.13.0             
dash-html-components      1.1.1   
dash-renderer             1.8.3  
dash-table                4.11.0   

@nukescott
Copy link

still broken in:
dash 1.19.0
dash-core-components 1.15.0
dash-html-components 1.1.2
dash-renderer 1.9.0
dash-table 4.11.2

@alexcjohnson
Copy link
Collaborator

We've been discussing internally whether there's a better way to handle this, but as a workaround in dash 1.19, due to #1525, you should be able to set clickData to None or some such as the output of your callback, then repeated clicks will register.

@app.callback(
    Output('clickDataDisplay', 'children'),
    Output('pie', 'clickData'),
    Input('pie', 'clickData')
)
def display_click_data(clickData):
    print("Processing click data.")
    return json.dumps(clickData, indent=2), None

@nukescott
Copy link

Adding an Output with clickData, and returning None does indeed avoid the problem. Thanks so much!

@pmkroeker
Copy link

pmkroeker commented Apr 6, 2021

We've been discussing internally whether there's a better way to handle this, but as a workaround in dash 1.19, due to #1525, you should be able to set clickData to None or some such as the output of your callback, then repeated clicks will register.

@app.callback(
    Output('clickDataDisplay', 'children'),
    Output('pie', 'clickData'),
    Input('pie', 'clickData')
)
def display_click_data(clickData):
    print("Processing click data.")
    return json.dumps(clickData, indent=2), None

When I try this I get a an error in the browser.

"Same Input and Output"

The same solution was proposed for this issue, but the same problem happened. Is there a way to prevent those errors? They cause the entire dashboard to not render.

Using dash 1.18. Is that possibly the problem?

EDIT:

Yes that was the problem, upgrading to 1.19 fixed it.

@nphausg
Copy link

nphausg commented Dec 28, 2022

It works on dash:2.7.1

hlmore added a commit to INM-6/beaverdam that referenced this issue Jul 18, 2023
Clicking the same figure section in a pie chart or bar graph multiple
times in a row doesn't fire the callback.  So if a section was clicked,
then the reset button was clicked, then the same section was clicked
again, nothing would happen.

The workaround is to reset the figure's clickData property to None
after each callback.

This may cause problems in future if we need to increment clickData,
e.g. to keep track of how many times something has been selected.

The bug and workaround are described here:
plotly/dash#1300
@gvwilson
Copy link
Contributor

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are most important to our community. If this issue is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. (Please note that we will give priority to reports that include a short reproducible example.) If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

@JulianoLagana
Copy link

This is still a problem in dash 2.15.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants