Black Lives Matter. Please consider donating to Black Girls Code today.

R plotly button


I want to creat a graph in plotly and i want a button to change de marker type in updatemenus, like square and circle and cross

Can you help me with a example?

Thanks :wink:

Hi @afrc

You can try something like below. For more examples see Plotly’s docs


df <- data.frame(x = c(1,2,3,4,5), y1 = c(5,5,5,5,5))

p <- plot_ly(df, x = ~x, y = ~y1, mode = 'markers')

p <- p %>% layout(
  title = "Button Restyle",
  xaxis = list(domain = c(0.1, 1)),
  yaxis = list(title = "y"),
  updatemenus = list(
      type = "buttons",
      y = 0.8,
      buttons = list(
        list(method = "restyle",
             args = list("marker.symbol", "circle"),
             label = "Circle"),
        list(method = "restyle",
             args = list("marker.symbol", "square"),
             label = "Square")))
1 Like

thanks a lot :wink:
got it !!!