Treemap level click interactions

I’m having a little trouble with a Treemap figure constructed in GO for a dash dashboard

The illustration is to show a the demographics in a City broken down by Ethnic group and giving the user the ability to drill down level by level to get more of it broken down

Level one is the over arching ethnic group eg White in the City
Level Two is the sub categories - White Irish within the City
Level Three - Age groups of White Irish
Level Four - Broken down by area in the City the selected age group of White Irish living in each area

This is where I have issues. The graph should stop having clickable interactions instead when clicked the interaction goes the smallest group

The Dataset can be accessed here: Census_Test.csv

My code to build the tree has a little function to format the numbering on the labels and from the dataset created a few lists which are used to create the figure:

import pandas as pd 
import plotly.graph_objects as go 

def format_int_with_commas(x):
    """
    Formats an integer with commas as thousand separators.
    """
    x = int(x)
    return f"{x:,}"

df = pd.read_csv('Census_Test.csv', index_col='Unnamed: 0')

#tree figure 
parents = [""] + [""] + df.parent.to_list()
labels = [""] + ["Glasgow"] + df.label.to_list()
values = [0] + [df[df.area == 'Glasgow_Total'].value.sum()] + df['value'].to_list()       
coloursBG = ["#d3d3d3"] + ["#949494"] + df.color.to_list()
hovers = [""] + [f"Glasgow All People {format_int_with_commas(df[df.area == 'Glasgow_Total'].value.sum())} <extra></extra>"] + df.hover.to_list()


fig = go.Figure(go.Treemap(
            branchvalues='total',
            values= values,
            labels = labels,
            parents = parents,
            hovertemplate=hovers,
            maxdepth=2,
            marker={'line.width' : 3, 
                    'colors' : coloursBG},
            textinfo='label+value',
            ))

fig
        

I’ve been stumped on this so any advice is appreciated

Hi @datadick ,

I think you need to make each value of ‘label’ column in the Forth Group unique each parent.
For example by adding parent name in the label ( change into “White: White Irish 25 - 34: Langside” instead of just “Langside”)

...

df = pd.read_csv('Census_Test.csv', index_col='Unnamed: 0')

# modify the label name in the Forth Group area
df['label'] = [val["parent"]+": "+val["label"] if val['area'] == 'Forth_Group' else val["label"] for _,val in df.iterrows()]

...

Spot on analysis. I cant tell you how long I’ve puzzled on this. Thank you so much