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

withProgressWaitress and incProgressWaitress not responding to max #123

Open
tvedebrink opened this issue Jun 10, 2022 · 1 comment
Open

Comments

@tvedebrink
Copy link

Hi John

I've been trying to use your intuitive package for showing a progress on a slow computation. After finishing the computations, the user should be able to download the results. However, it seems to me that the progress bar isn't reacting to my specified max (greater than 100) number of calculations. The example below shows an example, where the bar reaches 100% before the process reaches N. I've been trying to fiddle around with various hacks involving manual setting of the increment (to 1/N) and also providing the session to the incProgressWaitress function. But nothing really works as intended. I hope you can find my bug??

Best wishes,
Torben

library(shiny)
library(shinyjs)
library(waiter)

ui <- fluidPage(
  useWaitress(),
  useShinyjs(),
  br(),
  actionButton(
    "load",
    "Load stuff"
  ),
  shinyjs::disabled(downloadButton(
    "dwnload",
    "Download"
  ))
)

hep_hep <- function(n, .session){
  incProgressWaitress(100/n, session = .session)
  Sys.sleep(10/n)
}

hep_hep_ <- function(n){
  incProgressWaitress(1)
  Sys.sleep(10/n)
}

hep_hep__ <- function(n, .session){
  incProgressWaitress(1, session = .session)
  Sys.sleep(10/n)
}

N <- 150

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

  output$dwnload <- downloadHandler(
    filename = function() {
      paste('data-', Sys.Date(), '.csv', sep='')
    },
    content = function(con) {
      write.csv(hit_me, con)
    }
  )

  observeEvent(input$load,{
    withProgressWaitress({
      for (i in 1:N) {
        hep_hep(N, .session = session)
        print(i)
      }
    }, selector = "#dwnload", max = N, theme = "overlay-percent")
    shinyjs::enable("dwnload")
    hit_me <<- mtcars
  })
}

shinyApp(ui, server)
@tvedebrink
Copy link
Author

A sort of solution - rather than invoking the incProgressWaiter with an adjusted amount it is only activated when the increment is bigger than a 1% of the total calculation:

library(shiny)
library(shinyjs)
library(waiter)

ui <- fluidPage(
  useWaitress(),
  useShinyjs(),
  br(),
  actionButton("load", "Load stuff"),
  shinyjs::disabled(downloadButton("dwnload","Download"))
)

hep_hep_fix <- function(trick = FALSE, n, .session){
  if(trick) incProgressWaitress(value = 1, session = .session)
  Sys.sleep(10/n)
}

N <- 150

server <- function(input, output, session) {
  output$dwnload <- downloadHandler(
    filename = function() {
      paste('data-', Sys.Date(), '.csv', sep='')
    },
    content = function(con) {
      write.csv(hit_me, con)
    }
  )

  observeEvent(input$load,{
    withProgressWaitress({
      for (i in 1:N) {
        hep_hep_fix(trick = floor(i*100/N) > floor((i-1)*100/N), n = N, .session = session)
      }
    }, selector = "#dwnload", max = N, theme = "overlay-percent")
    shinyjs::enable("dwnload")
    hit_me <<- mtcars
  })
}

shinyApp(ui, server)

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

No branches or pull requests

1 participant