I am trying to update multiple data attributes in a figure generated via plotly
.
This is my script based on this post:
library(plotly)
library(magrittr)
library(data.table)
X <- data.table(x = c(1, 2, 1, 2), y = c(1, 1, 2, 2), z = rep(c("a", "b"), each = 2))
gg <- ggplot() + geom_point(data = X, aes(x = x, y = y, color = z))
ggplotly(gg) %>%
layout(
updatemenus = list(
list(
buttons = list(
list(method = "restyle",
args = list(
list(x = list(X[z == "a", x])),
list(y = list(X[z == "a", y]))
),
label = "a"),
list(method = "restyle",
args = list(
list(x = list(X[z == "b", x])),
list(y = list(X[z == "b", y]))
),
label = "b")
)
)
)
)
However, as can be seen, the update menu does not work as intended. Not sure what the problem is.