restyleData doesn't trigger the legend selected with Pie charts

Hello :),

I’m trying to catch the legend selection in a pie chart and this return me None.
I tried to do to the same with the legend of a scatter plot and it was ok .

Here is what I tried :

@app.callback(
             Output('seletedItem','children'),
              [Input('pie_chart','restyleData')])
def getSelectedLegend(selected):
       print(selected)
       raise PreventUpdate

Anyone can help me ?

Hi Josiias. I’m having the same problem. Did you solve it?

I encountered this problem as well. I’ve just created a feature request for it in the following thread:

2 Likes

I have been struggling with this for the last couple of hours aswell. Anyone found a solution?

Diving into the issue it seems to me to be due to the difference in pie plots structure compared to a scatter plot as an example, as on the scatter each series are plotted as a trace, whereas in the pie plot it is one collective trace.

Scatter trace example (figure[‘data’][0]):
{‘x’: [1, 2, 3, 4], ‘y’: [4, 1, 3, 5], ‘text’: [‘a’, ‘b’, ‘c’, ‘d’], ‘customdata’: [‘c.a’, ‘c.b’, ‘c.c’, ‘c.d’], ‘name’: ‘Trace 1’, ‘mode’: ‘markers’, ‘marker’: {‘size’: 12}, ‘visible’: True}

Pie Example (figure[‘data’][0]):
{‘hole’: 0.3, ‘labels’: [‘Oxygen’, ‘Hydrogen’, ‘Carbon_Dioxide’, ‘Nitrogen’], ‘values’: [4500, 2500, 1053, 500], ‘visible’: True, ‘type’: ‘pie’}

It would be super with some option to count each label-value pair as a trace or similar so this functionality is usable for Pie plots aswell :slight_smile:

UPDATE: I have found a workaround to achieve similar functionality:

@app.callback(
    Output('click-data', 'children'),
    Input('basic-interactions', 'relayoutData'), 
    State('basic-interactions', 'figure')
)
def display_restyle_data(restyleData, figure):
    #print(restyleData)
    if restyleData and 'hiddenlabels' in restyleData.keys():
        hidden_options = restyleData['hiddenlabels']
        print(hidden_options)
        return hidden_options