Making pb_elapsed update independently of new progress (like pb_spin)
Closed this issue · 4 comments
When I have a bar of format:
{cli::pb_spin} {cli::pb_bar} {cli::pb_percent} [ETA: {cli::pb_eta}] [Elapsed: {cli::pb_elapsed}]
The elapsed time is static between updates of the new-progress-dependent elements (bar, percent, eta), which feels odd UI-wise, especially given that the spinner can update more rapidly and independently of the new-progress-dependent elements. Am I missing an obvious way to make the pb_elapsed element update independently of new progress?
Edit: huh, updates to pb_spin is also new-progress-dependent; thought I remembered seeing it moving between progress updates but seems my memory was flawed.
It does update for me:
library(cli)
fun <- function() {
fmt <- "{cli::pb_spin} {cli::pb_bar} {cli::pb_percent} [ETA: {cli::pb_eta}] [Elapsed: {cli::pb_elapsed}]"
cli_progress_bar(format = fmt, total = 100)
cli_progress_update(inc = 1)
for (i in 1:1000) {
cli_progress_update(inc = 0)
Sys.sleep(0.1)
}
}
fun()
OK, then maybe it's about how cli is being used by purrr, bc this is how I use it and don't see updates:
options(
cli.progress_show_after = 0
, cli.progress_clear = FALSE
, cli.progress_bar_style = 'dot'
, cli.progress_format_iterator = "{cli::pb_spin} {cli::pb_bar} {cli::pb_percent} | ETA: {cli::pb_eta} | Elapsed: {cli::pb_elapsed}"
)
map(
.x = 1:10 %>% as.list()
, .f = ~ Sys.sleep(1)
, .progress = T
)
Oh, I just realized I'm too used to the progress from parallel compute which has an async orientation not applicable to a single R session as the cli/purrr combo aims at. Sorry for my confusion!
Yeah, hopefully in the future we'll be able to update the progress bar from another thread, but this is quite tricky in R, and currently we don't do it.