disable toggle in Plotly Pie chart

I want to disable the toggle of the legends on the right side. Still show the legends. The toggle does not make sense to me, it changes the percentage.

library(plotly)
# Data Preparation
labels = c('Beverage','Vegetable','Dairy','Fish')
values = c(4500, 2500, 1053, 500)
# Data Visualization
fig <- plot_ly(type='pie', labels=labels, values=values, 
               textinfo='label+percent',
               insidetextorientation='radial')
fig <- fig %>% layout(title = "Number of Sales by Parts of Supermarket in a Day")
fig

Even with this, layout | R | Plotly , it does not help.

Clicking the legend in plotly chart toggles whether to include that section so the percentages change to show each section as a % of the remaining total. Double clicking toggles to hide everything except what you double clicked.

You can disable this functionality with legend.itemclick and legend.itemdoubleclick in layout():

fig <- fig %>% layout(title = "Number of Sales by Parts of Supermarket in a Day",
                      legend = list(itemclick = FALSE,
                                    itemdoubleclick = FALSE))
1 Like

Splendid, that is what I need exactly, Thank you very much, Mr Cnbrownlie

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.