I would like to filter a chart created with plotly, based on a column of discrete values in my data. The end goal is to be able to use buttons to update the filter value, so I do not want to filter the data beforehand.
library(plotly)
df <- data.frame(group1 = rep(c('low', 'high'), each = 25),
x = rep(1:5, each = 5),
group2 = letters[1:5],
y = c(runif(25, 0, 2), runif(25, 3, 5)))
plot_ly(df, x = ~x, y = ~y, type = 'scatter',
mode = 'line',
color = ~group2,
transforms = list(
list(
type = 'filter',
target = ~group1,
operation = '=',
value = 'high'
)
)
)
I expected this to give the following chart:
but instead it gives this:
It seems to be filtering on the wrong variable. Why isn't the data being filtered the way I expect?

