Hello,
My first question so please be gentle! I’m a recent convert to plotly. I’ve created a figure that is based on the example given in the ‘Sine Wave Slider’ in the plotly examples.
What I want to do is update the chart title when the slider changes. This is what I have so far… it adds a title but doesn’t change with the slider.
Can anyone help!?
library(plotly)
x <- seq(0,10, length.out = 1000)
# create data
aval <- list()
for(step in 1:11){
aval[[step]] <-list(visible = FALSE,
name = paste0('v = ', step),
x=x,
y=sin(step*x))
}
aval[3][[1]]$visible = TRUE
# create steps and plot all traces
steps <- list()
p <- plot_ly()
for (i in 1:11) {
p <- add_lines(p,x=aval[i][[1]]$x, y=aval[i][[1]]$y, visible = aval[i][[1]]$visible,
name = aval[i][[1]]$name, type = 'scatter', mode = 'lines', hoverinfo = 'name',
line=list(color='00CED1'), showlegend = FALSE) %>%
layout(title = paste('title is',i))
step <- list(args = list('visible', rep(FALSE, length(aval))),
method = 'update')
step$args[[2]][i] = TRUE
steps[[i]] = step
}
# add slider control to plot
p <- p %>%
layout(sliders = list(list(active = 3,
currentvalue = list(prefix = "Frequency: "),
steps = steps)))