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 pie charts #1663

Closed
satyan-g opened this issue Jun 4, 2021 · 2 comments · Fixed by #1942
Closed

[BUG] customdata is missing in clickData for pie charts #1663

satyan-g opened this issue Jun 4, 2021 · 2 comments · Fixed by #1942

Comments

@satyan-g
Copy link

satyan-g commented Jun 4, 2021

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

  • replace the result of pip list | grep dash below
dash                      1.19.0
dash-alternative-viz      0.0.1               /home/satya/Downloads/dash-alternative-viz-master
dash-bootstrap-components 0.12.2
dash-core-components      1.15.0
dash-html-components      1.1.2
dash-renderer             1.9.0
dash-table                4.11.2

pie charts clickData is missing customdata and ids

I am trying to implement cross filtering between scatter plots and pie charts using selectedData and clickData respectively. Click data for pie charts has pointNumbers but not customdata or ids. I need some way to keep track of the index from the unfiltered data set.

As per documentation of go.Pie, customdata is meant for this task, but it is not behaving as expected. Sample code is attached.

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

# This dataframe has 244 lines, but 4 distinct values for `day`
df = px.data.tips()
df['id'] = df.index
print(df.columns)
app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Graph(id="pie-chart", figure=go.Figure(data=[go.Pie(labels=df['day'],  ids=df['id'].map(str), customdata=df['id'])])),
    dcc.Textarea(id='textArea')
])

@app.callback(
    Output("textArea", "value"), 
     Input('pie-chart', 'clickData'))
def handleClick(clickData):
    return str(clickData)

app.run_server(debug=True)
@satyan-g satyan-g changed the title [BUG] [BUG] customdata missing in clickData for pie charts Jun 4, 2021
@satyan-g satyan-g changed the title [BUG] customdata missing in clickData for pie charts [BUG] customdata is missing in clickData for pie charts Jun 4, 2021
@limbothai
Copy link

limbothai commented Apr 3, 2023

Hello,
Following up on this thread, I run into a very similar problem when using Scatter objects in Dash.

I'm using the following packages:

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

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)

As one can see on the screenshot below, when clicking on an object, clickData contains its point values, but not the custom data information. It seems like a similar bug as the one depicted for go.Pie above.

customdata_missing

@hs3308
Copy link

hs3308 commented May 31, 2024

I'm running into the same issue and it's driving me up a wall!

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

Successfully merging a pull request may close this issue.

3 participants