Hello!
I am generating two animations (GIF files) in an app. However, the files also open in Preview on a map as well as the app. How do I stop the files from opening outside of the app, please?
library(shiny)
library(animation)
ui <- fluidPage(
radioButtons(inputId="stype", "Choose First or Second:",
choices=c("First" = "first",
"Second" = "second")),
actionButton("resetMean", "Reset Data"),
plotOutput(outputId="init1"),
imageOutput("myImage"),
plotOutput(outputId="mean5"),
imageOutput("myBigImage"),
plotOutput(outputId="mean25")
)
server <- function(input, output, session) {
rv <- reactiveValues(x=NULL)
dataInput <- reactive({
observeEvent(input$resetMean, {
session$reload()
return()
})
observeEvent(input$init1, {
rv$x <- dataInput()$x
rv$y <- dataInput()$y
})
})
output$init1 <- renderPlot({
g <- function() {
.y1 <- rnorm(mean=16,sd=5,10000)
print(mean(.y1))
hist(.y1)
.s1 <- sample(.y1,5)
.s2 <- sample(.y1,25)
zzz <- list(x=.s1)
print("inside test")
rv$x <- .s1
rv$y <- .s2
return(zzz)
}
g()
print("stuff")
print(str(rv$x))
print("dataInput")
print(str(dataInput()$x))
})
output$myImage <- renderImage({
if(length(rv$x)==0) {
.y2 <- rep(NA,5)
hist(.y2,breaks=0:36,xlim=c(0,36),ylim=c(0,6))
}
if(length(rv$x)!=0) {
n1 <- 5
#img(src="erin2.gif", align = "left",height='500px',width='500px')
xlim1 <- max(36, ceiling(max(rv$x)))
print("numb")
print(xlim1)
outfile <- tempfile(pattern="erin1",fileext = '.gif')
# Generate the GIF
saveGIF(
for(i in 1:n1)hist(rv$x[1:i],breaks=0:xlim1,xlim=c(0,xlim1),ylim=c(0,6)),outfile)
}
# Return a list containing the filename
list(src = outfile,
contentType = 'image/gif',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
output$myBigImage <- renderImage({
if(length(rv$y)==0) {
.y2 <- rep(NA,5)
hist(.y2,breaks=0:36,xlim=c(0,36),ylim=c(0,6))
}
if(length(rv$y)!=0) {
n1 <- 25
#img(src="erin2.gif", align = "left",height='500px',width='500px')
xlim1 <- max(36, ceiling(max(rv$x)))
print("numb")
print(xlim1)
outfile <- tempfile(pattern="erin2",fileext = '.gif')
# Generate the GIF
saveGIF(
for(i in 1:n1)hist(rv$y[1:i],breaks=0:xlim1,xlim=c(0,xlim1),ylim=c(0,6)),outfile)
}
# Return a list containing the filename
list(src = outfile,
contentType = 'image/gif',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
output$mean5 <- renderPlot({
m5 <- rep(NA,5)
m5 <- mean(rv$x)
print(rv$x[1:5])
xlim1 <- max(36, ceiling(max(rv$x)))
hist(m5,breaks=0:xlim1,xlim=c(0,xlim1),ylim=c(0,6))
}
)
output$mean25 <- renderPlot({
m25 <- mean(rv$y)
xlim1 <- max(36, ceiling(max(rv$x)))
print(rv$y[1:5])
hist(m25,breaks=0:xlim1,xlim=c(0,xlim1),ylim=c(0,6))
}
)
}
shinyApp(ui, server)
Thanks in advance for any help.
Sincerely,
Erin