🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Update buttons not working on plotly R charts

I am trying to use the update buttons in plotly r charts where in the user can change the chart type to group or stacked. The group bar chart works for the first time but stacked never works. Below is the code I am using.

library(plotly)

Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo)

chart_types <- list(
  type = "buttons",
  direction = "right",
  xanchor = 'center',
  yanchor = "top",
  pad = list('r'= 0, 't'= 10, 'b' = 10),
  x = 0.5,
  y = 1.27,
  buttons = list(
        list(method = "restyle",
         args = list("type", "stack"),
         label = "Stack"),
    list(method = "restyle",
         args = list("type", "group"),
         label = "Group")
  ))

p <- plot_ly(data, x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF Zoo') %>%
  add_trace(y = ~LA_Zoo, name = 'LA Zoo')%>% layout(updatemenus = list(chart_types))
p