Skip to content

shiny progress support - #331

Open
the-mad-statter wants to merge 2 commits into
thomasp85:mainfrom
the-mad-statter:master
Open

shiny progress support#331
the-mad-statter wants to merge 2 commits into
thomasp85:mainfrom
the-mad-statter:master

Conversation

@the-mad-statter

@the-mad-statter the-mad-statter commented Jun 12, 2019

Copy link
Copy Markdown

Added support for shiny progress indicator based on the RStudio complex example. This pull request directly addresses issue #305 and partially addresses issue #272.

Comments were used in the travis yaml to avoid a pull-irrelevant build error involving deployment keys back to Github. I guess this change also resulted in the codecov errors. These changes can and should be ignored.

Progress message and detail were coded to best match the progress::progress_bar message using prettyunits::vague_dt(), but the decision to include prettyunits as a dependency is left up for debate. As it stands now, the user will have to library(prettyunits) in their app code to make this work.

This solution also requires the length of the progress bar in frames to be determined and set when making the shiny::Progress object and this value should also be passed to annimate().

Example app:

library(gapminder)
library(gganimate)
library(ggplot2)
library(prettyunits)
library(shiny)

ui <- fluidPage(
  imageOutput("plot_image")
)

server <- function(input, output) {
  
  output$plot_image <- renderImage({
    
    # as per https://shiny.rstudio.com/articles/progress.html#a-more-complex-progress-example
    # but set max value to pre-determined total frame count
    progress <- shiny::Progress$new(max = 100)
    progress$set(message = "Rendering", value = 0)
    on.exit(progress$close())
    
    updateShinyProgress <- function(detail) {    
      progress$inc(1, detail = detail)
    }
    
    outfile <- tempfile(fileext='.gif')
    
    p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
      geom_point(alpha = 0.7, show.legend = FALSE) +
      scale_colour_manual(values = country_colors) +
      scale_size(range = c(2, 12)) +
      scale_x_log10() +
      facet_wrap(~continent) +
      labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
      transition_time(year) +
      ease_aes('linear')
    
    # use animate() to control nframes and pass shiny progress update function
    anim_save("outfile.gif", animate(p, nframes = 100, update_progress = updateShinyProgress))
    
    list(src = "outfile.gif",
         contentType = 'image/gif', 
         width = 400,
         height = 400,
         alt = "This is alternate text"
    )}, deleteFile = TRUE)
}

shinyApp(ui, server)

@jschoeneberger

Copy link
Copy Markdown

Hi @schuelkem, when i try to run your code, i get the following error:

Warning: Error in device: unused argument (update_progress = function (detail)
{
progress$inc(1, detail = detail)
})
[No stack trace available]

Is there some piece of code that i'm missing? I have an animated line plot based on 100 rendered frames and am looking for a progress bar to alert users that work is happening in the background. I'm fairly certain that's what this is supposed to do (still a newbie). Can you help clarify what's missing here?

@the-mad-statter

Copy link
Copy Markdown
Author

Hi @jschoeneberger, I get the same error when I try to run my example app using an install of gganimate from the master branch of thomasp85/gganimate. The example app above requires a different version of gganimate to function. That version is a fork at schuelkem/gganimate. To install use devtools::install_github('schuelkem/gganimate').

@jschoeneberger

Copy link
Copy Markdown

Thanks a lot @schuelkem ! This works just fine, now...both with your example and in my app. Much appreciated!

@mortezatm

Copy link
Copy Markdown

Hi @jschoeneberger, I get the same error when I try to run my example app using an install of gganimate from the master branch of thomasp85/gganimate. The example app above requires a different version of gganimate to function. That version is a fork at schuelkem/gganimate. To install use devtools::install_github('schuelkem/gganimate').

This works on my local machine, but when I deploy the app on shinyapps.io, I get error. Any idea to fix it?

@jschoeneberger

Copy link
Copy Markdown

I'm not sure what to say...i'd try removing the old version and using a clean devtools installation. Good luck!

@ShinyFabio

Copy link
Copy Markdown

Any news?

@AndyBunn

AndyBunn commented Feb 7, 2025

Copy link
Copy Markdown

Love to see this merged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants