Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of shiny progress indicators with animate? #305

Open
ixodid198 opened this issue Mar 11, 2019 · 1 comment
Open

Use of shiny progress indicators with animate? #305

ixodid198 opened this issue Mar 11, 2019 · 1 comment

Comments

@ixodid198
Copy link

I have a shiny app that allows a user to create an animated gif. This takes some time. Is it possible to use a shiny progress indicator to provide feedback to the user?

The code below uses a "please wait" indicator from shinycssloaders. However, a progress bar would convey more information.

library(shiny)
library(tidyverse)
library(gganimate)
library(shinycssloaders)

ui <- fluidPage(
  plotOutput("anim_plot") %>% withSpinner(color="red", type = 6),
  
  fluidRow(
    column(3,  
           actionButton("make_plot", "Create")
    )
  )
)

server <- function(input, output, session) {
  library(shiny)

  output$anim_plot <- renderImage({
    list(src = "www/tmp/sq_border.png",
         contentType = 'image/png',
         height = 400,
         width = 400
    )
  }, deleteFile = FALSE)
  
  plot <- function(){
    ggplot(mtcars, aes(factor(cyl), mpg)) + 
      geom_boxplot() + 
      
      transition_states(
        gear,
        transition_length = 2,
        state_length = 1
      )  
  }
  
  make_gif <- function(p, speed){
    animate(p, nframes = speed, fps = 20,
            renderer = gifski_renderer(loop = FALSE), start_pause = 15)
  }
  
  # Button Pressed
  observeEvent(input$make_plot, {
    output$anim_plot <- renderPlot({
      p <- plot()
      speed <- 60
      ani <- make_gif(p, speed)  
      
      # Save animated gif
      anim_save(filename = "www/tmp/ani.gif", animation = ani)
      
      output$anim_plot <- renderImage({
        list(src = "www/tmp/ani.gif",
             contentType = 'image/gif')
      }, deleteFile = FALSE)  
    })
  })
}  

shinyApp(ui = ui, server = server)  
@AndyBunn
Copy link

Love to see this in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants