JohnCoene / waiter

🕰️ Loading screens for Shiny
https://waiter.john-coene.com/
Other
495 stars 25 forks source link

autoAttendant #137

Open kinto-b opened 1 year ago

kinto-b commented 1 year ago

Stellar package!

I think it would be handy to have an autoAttendantBar() which behaves similarly to autoWaiter(), i.e. it is shown on shiny:recalculating and closed on shiny:error or shiny:value.

Also, inspired by the behaviour of NProgress I think it would be more satisfying visually if:

  1. The automatic increase interval was not fixed but rather depended on the value of the progress bar so that the bar initially increases quickly and then slows down as we approach the end.

  2. The progress bar was finished off before being hidden when it is closed.

i.,e. this kind of behaviour:


# Increase by decaying interval
pbNext <- function(pb, x0 = 0.1, rate = 5) {
  next_val <- pb$getVal() + x0*exp(-rate*pb$getVal())
  pb$up(next_val)
}

# When finished, increase by random amount, wait, then increase to end
pbDone <- function(pb, ms = 100) {
  nextval <- pb$getVal() + runif(1, 0, 1-pb$getVal())
  pb$up(nextval)
  Sys.sleep(ms/1000)
  pb$up(1)
  close(pb)
}

pb <- utils::txtProgressBar()
while (pb$getVal() < 1) {
  Sys.sleep(0.1)

  # Imagine we hit `shiny:value` just after progbar crosses midway
  if (pb$getVal()<0.6) {
    pbNext(pb)
  } else {
    pbDone(pb)
  }
}

Relevant parts of NProgress here: https://github.com/rstacruz/nprogress/blob/e1a8b7fb6e059085df5f83c45d3c2308a147ca18/nprogress.js#L148-L177