yihui / animation

A gallery of animations in statistics and utilities to create animations

Home Page:https://yihui.org/animation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Animation in Shiny

Ellesar1 opened this issue · comments

I have a problem with getting a hold of the gif file produced by SaveGIF when deploying a Shiny app online. I should mention that I have asked this question on StackOverflow with no success and that Yihui recommended that I ask in here.

Below I show my attempt at an Shiny App. The goal is that the App takes an input dataset with location data and returns an animated gif of these data, either through downloading or rendering. There is probably something about the animation package and/or Shiny's internal file system I do not fathom. I would deeply appreciate a tip for a solution. The basic problem with the below code is that when deployed online it displays the message that "This is alternate text", but when run locally it works fine.

library(shiny)
library(animation)

#UI
ui <- basicPage(
imageOutput("plot1")
)

#Server
server <- function(input, output) {

data1_reactive <- reactive({
x <- c(1,2,3)
y <- c(2,4,5)
data_try <- data.frame(x,y)
return(data_try)
})

output$plot1 <- renderImage({
saveGIF(

for (i in 1:3) {
plot(data1_reactive()$x,data1_reactive()$y,type="p",col="black",xlim=c(0,10),ylim=c(0,10),pch=19)
lines(data1_reactive()[i,]$x,data1_reactive()[i,]$y,type="p",col="red",xlim=c(0,10),ylim=c(0,10),pch=19)

ani.pause()}, movie.name = 'test.gif', interval = 0.3,ani.width = 1400, ani.height = 900,outdir=tempdir())

# Return a list containing the filename
list(src = paste0(tempdir(),"/test.gif"),
contentType = 'image/gif',
alt = 'This is alternate text'
)}, deleteFile = FALSE)

}

shinyApp(ui, server)