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