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

Making pb_elapsed update independently of new progress (like pb_spin) #624

Closed
mike-lawrence opened this issue Aug 17, 2023 · 4 comments
Closed

Comments

@mike-lawrence
Copy link

mike-lawrence commented Aug 17, 2023

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.

@gaborcsardi
Copy link
Member

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()

@mike-lawrence
Copy link
Author

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
)

@mike-lawrence
Copy link
Author

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!

@gaborcsardi
Copy link
Member

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.

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

2 participants