'How to create a blinking circle in plotly using R / How to create an endless loop in plotly (they will amount to the same thing)?

I wish to create a blinking circle in plotly using R.

Here is my attempt:

library(plotly)

# Query:

# A 1000 frames with opacity alternating between .3 and 0

animation.df = data.frame(myyear=1:1000,myopacity = .3 * (1:1000 %%2 ))

> head(animation.df)
  myyear myopacity
1      1       0.3
2      2       0.0
3      3       0.3
4      4       0.0
5      5       0.3
6      6       0.0
>

p<- plot_ly()

p <- add_markers(p,data = animation.df,
                 marker= list(color="green",size=100,
                              sizemode="diameter",line=list(color="black",width =2)),
                 opacity=~myopacity,
                 frame=~myyear,
                 x = 1,
                 y = 1) %>% animation_slider(hide=T)

p

This is working for 1000 iterations.

How can I:

  1. Put this in an infinite loop?
  2. Hide the Play button?

Edit: I do not know how to do this in plotly, but I can use gganimate in R to do something equivalent. Like this:

library(ggplot2)
library(gganimate)

mydf = data.frame(opacity = c(0,.3),mystate = c(0,1))

myanimation <- ggplot(data = mydf)  +
    geom_point(aes(x=1,y=1),shape=21,color="black",size=30,stroke=2)+
    geom_point(aes(x=1,y=1,alpha = opacity,group=mystate),shape=21,fill= "green",
               size=30,show.legend=FALSE) +
    transition_states(states = mystate) +
    theme_void() + enter_appear() + exit_disappear()

animate(myanimation, fps=120, rewind=TRUE, height = 70, width=70)

anim_save("green.gif")

We may then insert this image as a background in Plotly.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source