I’m currently facing the same issue. The approach described here is not applicable for a few thousand rows of data.
I don’t have a fully working solution, but my idea was to adapt the x-axis range based on the slider value instead of re-using the data for each frame:
library(plotly)
DF <- data.frame(
x = seq(0, 12, length=50),
y = runif(n = 50, min = 0, max = 10)
)
steps <- list()
for(i in 1:13){
steps[[i]] <- list(args = list("xaxis", list(range = c(0, i))),
label = i,
method = "relayout",
value = i
)
}
# use animation_slider() / animation_button() / filter?
p <- plot_ly(DF, x = ~x, y = ~y, type = "scatter", mode = "lines") %>%
layout(title = "Cumulative Animations in R without data redundancy",
xaxis = list(range = steps[[1]]$args[[2]]$range),
sliders = list(
list(
active = 0,
currentvalue = list(prefix = "X-max: "),
pad = list(t = 60),
steps = steps)))
p
This unfortunately doesn’t provide us with the “Play”-button. But I thought it might be possible
to use animation_slider()
/ animation_button()
in a similar way?
Here is another interesting approach for the python api using filter.