Update Title When Using Transform to Filter Date

I’ve created a graph that lets you pick which group’s data to plot. I’d like to change the title when you pick the group, but I’m not sure how or if its possible. I’m having trouble learning which way to structure lists for certain plotly parameters. Even if I could add custom text to graph would probably work.

I think instead of using “restyle”, I should be using “update”, but when I try, the dropdown menu doesn’t work - I think maybe I have the list structure wrong but I can’t seem to get it right.

Code below so far

#Working Example so Far
library(plotly)

x <- c(1:100)
random_y <- rnorm(100, mean = 0)
random_y_prim <- rnorm(100, mean = 50)
mydata <- data.frame(x, random_y, random_y_prim, group = rep(letters[1:4], 25))

Make Group List Button

groupList <- unique(mydata$group)

groupLoop <- list()
for (iter in 1:length(groupList)) {
groupLoop[[iter]] <- list(method = “restyle”,
args = list(“transforms[0].value”, groupList[iter]),
label = groupList[iter])
}

Set up Axis labeling

f <- list(
family = “Verdana”,
size = 18,
color = “#7f7f7f
)

xLab <- list(
title = “x Axis”,
titlefont = f
)
yLab <- list(
title = “y Axis”,
titlefont = f
)

fig <- plot_ly(mydata, x = ~x, y = ~random_y
, type = ‘scatter’, mode = ‘lines’,
transforms = list(
list(
type = ‘filter’,
target = ~mydata$group,
operation = ‘=’,
value = groupList[1]
)
)
)

fig <- fig %>%
layout(
title = “Updating Practice”,
xaxis = xLab,
yaxis = yLab,
updatemenus = list(
list(
type = ‘dropdown’,xanchor = ‘center’,
yanchor = “top”,
active = 1,
buttons = groupLoop
)
)
)

fig