Highlight Line From List of Many IDs

I’m trying to add a dropdown button so that I can select one trace to highlight. A simplified version of my code in R is below. I have seen how to add a dropdown to change the style from say line to bar, but I don’t know how to change the style for just one of the id variables. Thanks!

library(tidyverse)
library(plotly)
set.seed(2001)

make 10 random data series
data <- data.frame(
t = rep(1:50, 10),
id = sort(rep(1:10, 50)),
y = rnorm(500)
)

cumulate the random variates by group
data <- data %>%
group_by(id) %>%
mutate(y2 = cumsum(y))

plot
plot <- data %>%
plot_ly(x = ~ t, y = ~y2, text = ~id) %>%
add_lines(split = ~id, color = I(‘gray’), alpha = 0.5) %>%
hide_legend()
plot

1 Like