✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🏦 Standard & Poor's chooses Dash Enterprise for ESG analysis. Learn why, sign up for the June 23 Webinar here!

Updating the 'values' of a chart using 'updatemenus' shows the wrong data even when hardcoded

I’m attempting to add a dropdown function to a sunburst chart in Plotly/Dash. The desired outcome is that a user can choose an option which will change the values used in the chart. I’ve read about doing it with callbacks but my current project structure would make that difficult (I didn’t know I’d be doing this).

I’ve seen instances of people using the ‘updatemenus’ attribute of the ‘update_layout’ method which worked for them.

For me, it changes the data displayed, however it displays data I do not expect to see.

Where I pass it data like [0.01, 0.014, 0.023, 0.004] it is displaying all the data as 1 or something equivalent where all values are equal - I can’t see what it’s displaying. The hover labels then go from displaying the value to just displaying %value%

I am using a dataframe named score_df with the following structure:

CompanyId | CompanyName  | FieldCluster | FieldValue | WEIGHT | WEIGHT_ADJUSTED_SCORE
--------------------------------------------------------------------------------
101237100 | CompanyName  | Cluster      | 10         |0.013382| 0.133820
103254894 | CompanyName2 | Cluster2     | 20         |0.014587| 0.145870

An extract of the code is below:

fig = px.sunburst(
    score_df, 
    path=['CompanyName', 'FieldCluster'], values='FieldValue' 
)

# Format the hover dialogue
fig.update_traces(
    go.Sunburst(hovertemplate='<b>%{label} - %{value}%</b> <br>%{parent}'),
    insidetextorientation='radial',       
)

weight = score_df['WEIGHT_ADJUSTED_SCORE'].tolist()

# Add button
fig.update_layout(
    updatemenus=[
        dict(active=0, 
        buttons=list([
                        dict(label="Adjusted by weight",
                             method="update",
                             args=[dict(                                 
                                    values=weight
                                    ),                            
                                  ]
                            ),                                               
        ])  
        )]
)

I have tried using:

values='WEIGHT_ADJUSTED_SCORE'

and:

values=score_df['WEIGHT_ADJUSTED_SCORE']

and also:

fig.update_layout(
    updatemenus=[
        dict(active=0, 
        buttons=list([
                        dict(label="Adjusted by weight",
                             method="restyle",
                             args=[{                        
                                    'values':weight
                                    },                            
                                  ]
                            ),                                               
        ])  
        )]
)

And they all have the same result. The initial chart is perfect until the dropdown option is selected.

I’ve even tried hardcoding the values as a test whereby I directly gave the values as different integers and it still does the same.

The expected result should have all the leaves of the sunburst as different sizes as they’re different values, but when the option is selected on the dropdown all the leaves become the same size.