I have an app that reloads an animated gif. It works fine in Safari and intermittently in Chrome. I believe the problem is similar to one mentioned here.
My knowledge of Javascript is negligible. However, reading this, I came up with this example, which still doesn't work. Using Chrome, if you click again enough times you will see that sometimes the image reload fails.
Because my knowledge of Javascript is negligible it would be helpful to me if someone could modify my R reproducible example rather than providing just Javascript code.
You can find an animated gif here
library(shiny)
library(shinyjs)
jsCode <- '
shinyjs.reset_anim = function() {
var src = "tmp/ani.gif";
var div_elem = document.getElementById("anim_plot");
var img_elem = div_elem.getElementsByTagName("img")[0];
var src_value = img_elem.getAttribute("src");
img_elem.setAttribute("src", "");
img_elem.setAttribute("src", src_value);
}
'
# Define UI ----
ui <- fluidPage(useShinyjs(),
extendShinyjs(text = jsCode),
plotOutput("anim_plot",
width = "900px",
height = "200px"),
fluidRow(
column(3,
actionButton("do_again", "Again")
)
)
)
# Define server logic ----
server <- function(input, output) {
observeEvent(input$do_again, {
js$reset_anim()
output$anim_plot <- renderImage({
list(src = "www/tmp/ani.gif",
contentType = 'image/gif',
width = 900,
alt = "Text"
)
}, deleteFile = FALSE)
})
}
shinyApp(ui = ui, server = server)