Linking traces in nested pie chart (for legend toggle functionality)

As part of a dashboard summarising disaster impact, we show nested pie charts which break the total damages down into portfolios (e.g. Transport) and then individual components (e.g. Roads, Railways). I’ll try to add a screenshot of one of them below.

I’m wondering if it’s possible to link the two traces (inner & outer donuts), so that clicking on a legend item to toggle off a portfolio item (inner donut) would also toggle off all that portfolio’s individual components (outer donut)? Or, if not, to disable the toggle functionality altogether?

In the simplified example below, could it be modified so that when a user clicks on the ‘Reds’ legend item, all of the red pie segments are toggled off (inner & outer donut)? Any suggestions would be much appreciated!

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go

data = [# Portfolio (inner donut)
               domain={'x':[0.2,0.8], 'y':[0.1,0.9]},
        # Individual components (outer donut)
               labels=['Medium Red','Light Red','Medium Blue','Light Blue'],
               domain={'x':[0.1,0.9], 'y':[0,1]},

# Run Dash app
app = dash.Dash()
app.layout = html.Div(dcc.Graph(figure=go.Figure(data=data, layout={'title':'Nested Pie Chart'})))

if __name__ == '__main__':

Look into the “legendgroup” property:

Hi @chriddyp, thanks for the suggestion. I’d spent a while playing with that before but couldn’t get it to work for this. For what I’m after, I think I’d need to pass in lists to the legendgroup property (e.g. legendgroup=['Reds','Blues'] for the first trace in my example, and legendgroup=['Reds','Reds','Blues','Blues'] for the second) but that doesn’t seem to work.

Assuming the legendgroup property only accepts a single string, would I need to try and build each pie chart segment by segment (if that’s possible), updating the rotation parameter for each trace as I go?