🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Plotly Sunburst returning empty chart with branchvalues = 'total'

Hi all!

I am having problems with the “plotly” package in R, in particular with the “sunburst” type of graph.

When I specify branchvalues = “remainder” the result is as expected (but not what I want), whereas when I specify branchvalues = “total” the result is an empty graph.

To illustrate this, please compare the following two R codes differing only in the “branchvalues” option:

labels = c(“Seth”, “Enos”, “Noam”, “Awan”, “Enoch”),
parents = c("", “Seth”, “Seth”, “”, “Awan”),
values = c(12, 10, 2, 4, 4),
type = ‘sunburst’,
branchvalues = ‘remainder’

labels = c(“Seth”, “Enos”, “Noam”, “Awan”, “Enoch”),
parents = c("", “Seth”, “Seth”, “”, “Awan”),
values = c(12, 10, 2, 4, 4),
type = ‘sunburst’,
branchvalues = ‘total’

The first one works, whereas the second one returns an empty graph.

Am I doing something wrong?

Any help is highly appreciated!!!



I’m having this exact same issue but with a bigger data set, the values are floats but each layer of the sunburst is exactly the same value of it’s parent, I can’t understand what’s going wrong

I’m experiencing the same issue. Code below. This appears to be a bug, since the same question has popped up in the plotly for Python forum topic as well.

sunburst_data <- data.frame(ids = c(1, 2, 3, 4, 5, 6, 7, 8, 9, “1 - a”, “1 - b”, “2 - a”, “2 - b”, “3 - a”, “3 - b”, “4 - b”, “5 - a”, “5 - b”, “6 - a”, “6 - b”, “7 - a”, “7 - b”, “8 - a”, “8 - b”, “9 - a”, “9 - b”),
labels = c(“Group 1”, “Group 2”, “Group 3”, “Group 4”, “Group 5”, “Group 6”, “Group 7”, “Group 8”, “Group 9”, “a”, “b”, “a”, “b”, “a”, “b”, “b”, “a”, “b”, “a”, “b”, “a”, “b”, “a”, “b”, “a”, “b”),
parents = c("", “”, “”, “”, “”, “”, “”, “”, “”,“1”, “1”, “2”, “2”, “3”, “3”, “4”, “5”, “5”, “6”, “6”, “7”, “7”, “8”, “8”, “9”, “9”),
values = c(195, 99, 2425, 3, 379, 5182, 48, 3119, 903, 37, 158, 15, 84, 561, 1864, 3, 67, 312, 915, 4267, 19, 29, 433, 2686, 51, 852), stringsAsFactors = F)
plot_ly(sunburst_data, ids=~ids, labels=~labels, parents=~parents, values=~values, type=“sunburst”, branchvalues=“total”)

1 Like

Could you post your answer on here, there is someone that might be looking into this issue

I tried the above sample data in Python and it rendered without error. I’ll try in R tomorrow to see if I get different results.

Hmm something odd is happening on the R side indeed. I’ll try to frame up an issue for the JS team.

1 Like

Hello, same issue here… Any update about the possibility of fixing it? Thanks for your help and best regards!

The plot renders fine once we add a “root”:


  labels = c("Eve", "Seth", "Enos", "Noam", "Awan", "Enoch"),
  parents = c("", "Eve", "Seth", "Seth", "Eve", "Awan"),
  values = c(16, 12, 10, 2, 4, 4),
  type = "sunburst",
  branchvalues = "total"


This seems to be related. Nevertheless, I filed an issue here.

Yes, it works! Thanks a lot!

Hello again,

Now I’m struggling with formating the data. I saw your answer to https://stackoverflow.com/questions/57395424/how-to-format-data-for-plotly-sunburst-diagram, so I’ve been formating my data as you describe:

       labels values         parents                           ids
 1:       total   1658            <NA>                         total
 2:     private    353           total               total - private
 3:      public   1120           total                total - public
 4:       mixed    185           total                 total - mixed
 5: residential    108 total - private total - private - residential
 6:  recreation    143 total - private  total - private - recreation
 7:  commercial    102 total - private  total - private - commercial
 8: residential    300  total - public  total - public - residential
 9:  recreation    320  total - public   total - public - recreation
10:  commercial    500  total - public   total - public - commercial
11: residential     37   total - mixed   total - mixed - residential
12:  recreation     58   total - mixed    total - mixed - recreation
13:  commercial     90   total - mixed    total - mixed - commercial

I don’t know data.table so much so I do it with dplyr, by grouping my data succesively:

DF0 <- DF %>% group_by(level0) %>% summarise(value=sum(value)
DF1 <- DF %>% group_by(level0, level1) %>% summarise(value=sum(value))
DF2 <- DF %>% group_by(level0, level1, level2) %>% summarise(value=sum(value))

Data frame with ids, parents… is created at each level, for example, level2:

ids = ~paste(DF2$level0, ‘-’, DF2$level1, ‘-’, DF2$level2),
labels = ~DF2$level2,
parents = ~paste(DF2$level0, ‘-’, DF2$level1),
values = ~DF2$value,
stringsAsFactors = F

I then bind all the resulting dataframes to get a structure like the one you describe.

NB: Level0 is a unique root (following your indication, thanks again for that!). Values total and subtotals are consistant…

But the plot just doesn’t show.

plot_ly(ids=~ids, labels=~labels, parents=~parents, values=~values, type=‘sunburst’, branchvalues=‘total’)

I agree that SunburstR provides a far better, straightforward way to do this - actually this is what I currently have implemented. But it hasn’t got the animation thing, which makes a lot of difference in my case (showing 6 levels of information).

So any help would be highly appreciated.

Thank you very much in advance!

It’s hard to tell what’s going wrong without seeing your (or similar dummy) data.
library(sunburstR) also provides an animated plot via sund2b() - here is an example.
However, I’m sure you can also solve it using plotly.

Hello @nicolaskruchten, I have a Python example that shows a similar issue - see https://github.com/mwouts/easyplotly/issues/3. Hopefully the example includes everything you need to reproduce. Rounding the data appears to solve the problem, so it may just be a float comparison that is a bit too strict in the JS library.

Ah, great, thanks so much @mwouts! I’ve been looking for a test case where things add up in Python but not JS… hard to find :slight_smile:

I’ve filed this issue in plotly.js to make things a bit looser: https://github.com/plotly/plotly.js/issues/4405

1 Like

Are you trying to plot floats? Maybe you have the same issue?

OK so there are two things going on here… With floats, we have the overly-strict behaviour described in https://github.com/plotly/plotly.js/issues/4405 which we will fix.

The issue reported at the very top by @NewToR is actually fixed in more recent versions of Plotly.js (it happens in Plotly.js v1.49.4) but unfortunately this hasn’t made its way to Plotly.R just yet.


Well, after converting the values to integer… It just works perfectly!

So I’ll implement the plotly Sunburst instead of the SunburstR - even if the sund2b() actually looks great, and defining links is way easier in sunburstR… I prefer to stick to Plotly and be consistent all along my dashboard.

Thank you very much mwouts, nicolaskrutchen, & ismirsegregal!

1 Like

Thank you Nicolas. I will wait for the fix to become available in R!

Hi Nicolas,

I am having the same problem with the sunburst chart in python. I’ve had even shaped my dataset exactly equal to the site example(Large Number of Slices), but still it doesn’t render.

Hi @nicolaskruchten, would you have any idea when this issue might be fixed in Plotly.R? The sunburst offered by Plotly works great for my dataset, but it’s a shame that the “branchvalues = total” option is not working.
Thanks in advance.