waiter icon indicating copy to clipboard operation
waiter copied to clipboard

autoAttendant

Open kinto-b opened this issue 2 years ago • 0 comments

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

kinto-b avatar Jun 30 '23 03:06 kinto-b