gganimate to create video and embed in R Shiny app

I'm trying to create an animation using gganimate and save it as an .mp4 using av_renderer and display it in a Shiny app. I've been able to get this to work as .gif, but I'd like to make it a movie instead if possible to allow for more playback controls of the video. Below is the code used to generate the .mp4 and I've confirmed this works by itself outside of the Shiny app. Should I be using something other than renderImage()? And how should I go about displaying this in the app?

    output$dispLayers <- renderImage({
        # A temp file to save the output.
        # This file will be removed later by renderImage
        outfile <- tempfile(fileext='.mp4')
            
        p <- layers %>%
            ggplot(aes(x = `X Position`, y = `Y Position`)) + 
            geom_raster(hjust = 1, vjust = 1, aes_string(fill = input$layer)) +
            scale_x_continuous(expand = c(0, 0), limits = c(0,100), 
                               name = "(mm)",
                               labels=c("0","0.5","1","1.5","2")) +
            scale_y_continuous(expand = c(0, 0), limits = c(0,100),
                               name = "(mm)",
                               labels=c("0","0.5","1","1.5","2")) +
            theme(aspect.ratio = 1) +
            transition_manual(layers$time, cumulative = FALSE) +
            labs(fill = '(pg/mL)', title = input$layer,
                 subtitle = 't = {current_frame} hours')
        
        anim_save("outfile.mp4", animate(p, renderer = av_renderer()))
        
        # Return a list containing the filename
        list(src = "outfile.mp4",
             contentType = 'video/mp4'
             #width = 800,
             #height = 800
             # alt = "This is alternate text"
        )}, deleteFile = TRUE)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.