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

Progress bars behind callr processes #755

Closed
wlandau opened this issue Apr 1, 2025 · 2 comments
Closed

Progress bars behind callr processes #755

wlandau opened this issue Apr 1, 2025 · 2 comments

Comments

@wlandau
Copy link

wlandau commented Apr 1, 2025

I'm really enjoying cli progress bars, but I'm struggling with an edge case. For ropensci/targets#1442, I need to run the progress bar behind a non-interactive callr process. Unfortunately, the non-interactivity seems to make the progress bar slightly less responsive, and it seems to spill over into multiple lines. This is the desired behavior when writing to a fixed log file, but it's counterintuitive when the parent session is interactive. Are there any workarounds etc.?

out <- callr::r(
  \() {
    library(cli)
    clean <- function() {
      options(cli.num_colors = 256)
      cli_progress_bar("Cleaning data", total = 100)
      for (i in 1:100) {
        Sys.sleep(5/100)
        cli_progress_update()
      }
      cli_progress_done()
    }
    clean()
  },
  show = TRUE,
  stderr = "2>&1"
)
#> Cleaning data ■■■■■■■                           19% | ETA:  4s
#> Cleaning data ■■■■■■■■■■■■■■■■■                 55% | ETA:  2s
#> Cleaning data ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | #> ETA:  0s
@gaborcsardi
Copy link
Member

Set the cli.dynamic = TRUE option in the subprocess.

@wlandau
Copy link
Author

wlandau commented Apr 1, 2025

Thanks! Works great on my end.

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