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] customdata is missing in clickData for Scatter objects #2493

Closed
limbothai opened this issue Apr 3, 2023 · 1 comment
Closed

[BUG] customdata is missing in clickData for Scatter objects #2493

limbothai opened this issue Apr 3, 2023 · 1 comment

Comments

@limbothai
Copy link

limbothai commented Apr 3, 2023

My environment

dash                          2.9.2
dash-bootstrap-components     1.4.1
dash-core-components          2.0.0
dash-html-components          2.0.0
dash-table                    5.0.0

The bug

This bug is very similar to another one that was fixed last year, described here https://github.com/plotly/dash/issues/1663 .

I want to retrieve a custom identifier (a string) linked to a scatter object, by clicking on it. As per documentation of go.Scatter, customdata is meant for this task, but it is not behaving as expected.

Here is a sample code:

import dash
from dash import html,dcc
from dash.dependencies import Input, Output
import plotly.express as px
import plotly.graph_objects as go
import json

app = dash.Dash(__name__)

fig=go.Figure(data=[go.Scatter(x=[0, 1, 1, 0, 0],y=[1, 1, 2, 2, 1],mode='lines',fill='toself',customdata=["obj-1"]),
                    go.Scatter(x=[3, 4, 4, 3, 3],y=[4, 4, 5, 5, 4],mode='lines',fill='toself',customdata=["obj-2"])])


app.layout = html.Div([
    dcc.Graph(id="scatter-object", figure=fig),
    dcc.Textarea(id='textArea')
])

@app.callback(
    Output("textArea", "value"), 
     Input('scatter-object', 'clickData'))
def handleClick(clickData):
    return json.dumps(clickData,indent=2)

app.run_server(debug=True)

Expected behavior

clickData should contain the customdata defined in the constructor of go.Scatter. Unfortunately it doesn't.

Screenshots

As one can see on the screenshot below, when clicking on an object, clickData contains its point values, but not the custom data information:

customdata_missing

@nickmelnikov82
Copy link
Member

Upgrading to the latest versions of plotly and dash will fix the issue when clickData does not contain customdata. The new versions have fixed this issue, and you will get the expected information from customdata when you click on a graph.

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

3 participants