🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Plot 3D trajectory with moving marker

I am using plotly in R to plot laser trajectory with moving marker. The marker is not moving during the whole animation. I thought this must be some parameter not setting correctly, but tried bunch of things, none of them working. The code is simplified as:

library(dplyr)
library(plotly)

r <- 5
rad <- seq(0, 2pi, by = 0.05)
dat <- data.frame(x = r
cos(rad),
y = r*sin(rad),
z = seq(0, r, length.out = length(rad)),
time = seq(1, r, length.out = length(rad)))

plot_ly(dat, x = ~x, y = ~y, z = ~z) %>%
add_paths() %>%
add_markers(frame = ~time, marker = list(size = 3, color = “black”)) %>%
animation_opts(frame = 1, redraw = FALSE)