R plotly button


#1

Hi.

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:


#2

Hi @afrc

You can try something like below. For more examples see Plotly’s docs https://plot.ly/r/#controls

library(plotly)

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(
    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")))
  ))

#3

thanks a lot :wink:
got it !!!