Skip to content

Commit be35fd3

Browse files
Shiny: prototype support for controlling Shiny target of 'sticky' progression updates [#109]
1 parent 6fe26e8 commit be35fd3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ SIGNIFICANT CHANGES:
1919

2020
NEW FEATURES:
2121

22+
* withProgressShiny() gained argument 'map', which can be used to control
23+
whether the progression message should update the Shiny 'message' or the
24+
Shiny 'detail' component in the Shiny progress panel, e.g.
25+
map = c(message = "message") or map = c(message = "detail").
26+
2227
* Now supporting zero-length progressors, e.g. p <- progressor(along = x)
2328
where length(x) == 0.
2429

R/handler_shiny.R

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,36 @@ handler_shiny <- function(intrusiveness = getOption("progressr.intrusiveness.gui
3434
)
3535

3636
## Default: The progression message updates Shiny 'message'
37-
map_args <- function(state) list(message = state$message)
37+
map_args <- function(state, progression) {
38+
message <- state$message
39+
if (is.null(message)) return(list())
40+
if (inherits(progression, "sticky")) {
41+
list(detail = message)
42+
} else {
43+
list(message = message)
44+
}
45+
}
3846

3947
## Should progress message update another Shiny field?
4048
if ("message" %in% names(map)) {
4149
if (map["message"] == "detail") {
42-
map_args <- function(state) list(detail = state$message)
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+
}
4359
}
4460
}
4561

4662
reporter <- local({
4763
list(
4864
update = function(config, state, progression, ...) {
4965
amount <- if (config$max_steps == 0) 1 else progression$amount / config$max_steps
50-
args <- c(list(amount = amount), map_args(state))
66+
args <- c(list(amount = amount), map_args(state, progression))
5167
do.call(shiny::incProgress, args = args)
5268
}
5369
)

0 commit comments

Comments
 (0)