Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Suggests:
rmarkdown,
rprojroot,
rstudioapi,
shiny,
testthat (>= 3.2.0),
tibble,
whoami,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
error when the progress bar is drawn with a value below zero or above
the total (#580, @taekop).

* `cli_progress_output()` no longer fails with the Shiny progress handler
if the progress bar has not been shown yet (#762, @taekop).

# cli 3.6.6

* New `{.num}` and `{.bytes}` inline styles to format numbers
Expand Down
10 changes: 6 additions & 4 deletions R/progress-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,12 @@ builtin_handler_shiny <- list(
output = function(bar, .envir, text) {
bar$shiny_output <-
last_lines(paste0(bar$shiny_output, " \u2022 ", text))
bar$shiny_progress$set(
value = bar$current,
detail = shiny_detail(bar, .envir)
)
if (!is.null(bar$shiny_progress)) {
bar$shiny_progress$set(
value = bar$current,
detail = shiny_detail(bar, .envir)
)
}
}
)

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-progress-handlers.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,18 @@ test_that("builtin_handlers", {
expect_true(is.list(builtin_handlers()))
expect_true(all(c("cli", "shiny", "rstudio") %in% names(builtin_handlers())))
})

test_that("shiny handler, cli_progress_output() before the bar is shown", {
skip_if_not_installed("shiny")
withr::local_options(
cli.progress_handlers_only = "shiny",
cli.progress_show_after = 3600
)
server <- function(input, output, session) {
id <- cli_progress_bar(total = 10)
cli_progress_output("custom message", id = id)
cli_progress_update(id = id)
cli_progress_done(id = id)
}
expect_no_error(shiny::testServer(server, {}))
})
Loading