I’m not really sure why this isn’t working. I am working on a larger example and the graph is not updating, here is a small example that is similar.
a <- data.frame (x = c(1,2,3,4,5,6,7,8,9,10),
y = c(1,2,3,4,5,6,7,8,9,10))
b <- data.frame(x = c(6,7,8,9,10,11,12,13,14,15),
y = c(6,7,8,9,10,11,12,13,14,15))
updatemenus <- list(
list(
#active = -1,
type = “buttons”,
buttons = list(
list(
label = “A”,
method = “update”,
args = list(list(“visible”, c(TRUE, FALSE)),
list(title = “A”))
),
list(
label = “B”,
method = “update”,
args = list(list(“visible”, c(FALSE, TRUE)),
list(title = “B”))
)
)
)
)
plot_ly() %>%
add_trace(data = a,
x = ~x,
y = ~y,
type = “scatter”,
mode = “markers”,
name = “A”,
visible = TRUE) %>%
add_trace(data = b,
x = ~x,
y = ~y,
type = “scatter”,
mode = “markers”,
name = “B”,
visible = FALSE) %>%
layout(updatemenus = updatemenus)