|
4 | 4 | #' |
5 | 5 | #' @inheritParams make_progression_handler |
6 | 6 | #' |
7 | | -#' @param map Specifies whether the progression message should be mapped |
8 | | -#' to the 'message' and 'detail' element in the Shiny progress panel. |
9 | | -#' This argument should be a named character string with value `"message"` |
10 | | -#' or `"detail"` and where the name should be `message`, e.g. |
11 | | -#' `map = c(message = "message")` or `map = c(message = "detail")`. |
| 7 | +#' @param inputs (named list) Specifies from what sources the Shiny progress |
| 8 | +#' elements 'message' and 'detail' should be updated. Valid sources are |
| 9 | +#' `"message"`, `"sticky_message"` and `"non_sticky_message"`, where |
| 10 | +#' `"message"` is short for `c("non_sticky_message", "sticky_message")`. For |
| 11 | +#' example, `inputs = list(message = "sticky-message", detail = "message")` |
| 12 | +#' will update the Shiny 'message' component from sticky messages only, |
| 13 | +#' whereas the 'detail' component is updated using any message. |
12 | 14 | #' |
13 | 15 | #' @param \ldots Additional arguments passed to [make_progression_handler()]. |
14 | 16 | #' |
|
27 | 29 | #' |
28 | 30 | #' @keywords internal |
29 | 31 | #' @export |
30 | | -handler_shiny <- function(intrusiveness = getOption("progressr.intrusiveness.gui", 1), target = "gui", map = c(message = "message"), ...) { |
| 32 | +handler_shiny <- function(intrusiveness = getOption("progressr.intrusiveness.gui", 1), target = "gui", inputs = list(message = NULL, detail = "message"), ...) { |
31 | 33 | stop_if_not( |
32 | | - is.character(map), all(map %in% c("message", "detail")), |
33 | | - !is.null(names(map)), all(names(map) %in% c("message")) |
| 34 | + is.list(inputs), |
| 35 | + !is.null(names(inputs)), |
| 36 | + all(names(inputs) %in% c("message", "detail")), |
| 37 | + all(vapply(inputs, FUN = function(x) { |
| 38 | + if (is.null(x)) return(TRUE) |
| 39 | + if (!is.character(x)) return(FALSE) |
| 40 | + x %in% c("message", "non_sticky_message", "sticky_message") |
| 41 | + }, FUN.VALUE = FALSE)) |
34 | 42 | ) |
35 | 43 |
|
| 44 | + ## Expand 'message' => c("non_sticky_message", "sticky_message") |
| 45 | + for (name in names(inputs)) { |
| 46 | + input <- inputs[[name]] |
| 47 | + if ("message" %in% input) { |
| 48 | + input <- setdiff(input, "message") |
| 49 | + input <- c(input, "non_sticky_message", "sticky_message") |
| 50 | + } |
| 51 | + inputs[[name]] <- unique(input) |
| 52 | + } |
| 53 | + |
36 | 54 | ## Default: The progression message updates Shiny 'message' |
37 | 55 | map_args <- function(state, progression) { |
38 | | - message <- state$message |
| 56 | + message <- progression$message |
39 | 57 | if (is.null(message)) return(list()) |
40 | | - if (inherits(progression, "sticky")) { |
41 | | - list(detail = message) |
42 | | - } else { |
43 | | - list(message = message) |
44 | | - } |
45 | | - } |
46 | 58 |
|
47 | | - ## Should progress message update another Shiny field? |
48 | | - if ("message" %in% names(map)) { |
49 | | - if (map["message"] == "detail") { |
50 | | - map_args <- function(state, progression) { |
51 | | - message <- state$message |
52 | | - if (is.null(message)) return(list()) |
53 | | - if (inherits(progression, "sticky")) { |
54 | | - list(message = message) |
55 | | - } else { |
56 | | - list(detail = message) |
57 | | - } |
58 | | - } |
| 59 | + ## Update Shiny 'message' and 'detail'? |
| 60 | + args <- list() |
| 61 | + for (target in c("message", "detail")) { |
| 62 | + if (inherits(progression, "sticky")) { |
| 63 | + if ("sticky_message" %in% inputs[[target]]) |
| 64 | + args[[target]] <- message |
| 65 | + } else { |
| 66 | + if ("non_sticky_message" %in% inputs[[target]]) |
| 67 | + args[[target]] <- message |
| 68 | + } |
59 | 69 | } |
| 70 | + |
| 71 | + args |
60 | 72 | } |
61 | 73 |
|
62 | 74 | reporter <- local({ |
|
0 commit comments