0

I am trying to use the shinyanimate package to continuously animate an image element in my shiny app.
I tried to use a while loop to check if the session was open, but I'm not sure why this approach is not working.

library(shiny)
library(shinyanimate)



ui <- fluidPage(
      
          withAnim(),
      
          div(id = "blood", 
              tags$img(src = "https://inews-prd-a-images.s3.eu-west-2.amazonaws.com/content/uploads/2019/02/Blood-droplet-640x360.jpg",
                       width = "100px", 
                       height = "100px")),
      
      
          # Application title
          titlePanel("Test app")
      
)



server <- function(input, output, session) {
      
          while (session$isClosed() == FALSE){
                
                    observe(startAnim(session, "blood", "pulse"))
                
          }
      
}


shinyApp(ui = ui, server = server)
mdb_ftl
  • 423
  • 2
  • 14

1 Answers1

0

I figured out the answer with a while loop within the observe call

library(shiny)
library(shinyanimate)




ui <- fluidPage(
      
          withAnim(),
      
          div(id = "blood", 
              tags$img(src = "https://inews-prd-a-images.s3.eu-west-2.amazonaws.com/content/uploads/2019/02/Blood-droplet-640x360.jpg",
                       width = "100px", 
                       height = "100px")),
      
      
          # Application title
          titlePanel("Test app"), 
      

      
)



server <- function(input, output, session) {
      
          observe({
                    while(TRUE){
                              startAnim(session, "blood", "pulse")
                    }
          })
}


shinyApp(ui = ui, server = server)
mdb_ftl
  • 423
  • 2
  • 14