Hi all,
I'm facing a strange problem when reloading an animated GIF that only shows when using Google Chrome (Firefox and Internet Explorer don't show the problem). I've tested it in Chrome 42.0.2311.90, Firefox 37.0.1 and Internet Explorer 9.0.8112.16421.
I want to include an animated GIF that shows a 1-second animation (it does not loop forever, i.e. it shows the animation and ends) in my Shiny application. More specifically, I want to show the animation every time an action button is pressed.
I have included in my ui.R file an imageOutput ("animated_image", the placeholder for the animated gif) and the corresponding actionButton ("show").
Then I have included the following code in my server.R file:
output$animated_image <- renderImage({
input$show
list(src="www/anim_1.gif")
}, deleteFile = FALSE)
when I load the application on Chrome, the animation only runs once (the first time the code is run). After that, whenever I press the button the image stays the same, just showing the last frame of the animated GIF. However, if I load it on Firefox or IE the application behaves as desired, i.e. the animation runs each time I press the button.
Fearing some problem related with image caching, I created a second version of the animated GIF with a slight modification in some pixels (so that it doesn't identify it as the same file) and stored it as "anim_2.gif". After that, I modified the code so that it loads alternatively the 1st or the 2nd version, hoping that the browser sees it as a different image than the previous one. This is the code (variable COUNT is previously initialized with 0):
output$animate_image <- renderImage({
COUNT <- COUNT + input$show
if (COUNT %% 2 == 0){filename="www/anim_1.gif"}
else {filename="www/anim_2.gif"}
list(src=filename)
}, deleteFile = FALSE)
In this case, the animation runs just twice (the first time the code is run, and after pressing the button for the first time). After that, it seems like Chrome detects that I'm trying to load an image that has already been loaded before (even if it is not the immediate previous one) and "refuses" to load the animation again. Firefox and IE still work fine.
I've also tried some solutions I found for related problems in other contexts, e.g. adding a random number as an additional parameter in the URL, like this:
list(src=paste0("www/anim_1.gif?x=",abs(rnorm(1))))
but that doesn't work in this case, as Shiny can't find the image with that tweaked URL.
Any ideas on how can I solve this problem that only shows in Chrome?
Thanks,
Mikel