Debian Codegraph @

R/snapshot.R

raw
1 #' Mark an output to be excluded from test snapshots
2 #'
3 #' @param x A reactive which will be assigned to an output.
4 #'
5 #' @export
6 snapshotExclude <- function(x) {
7 markOutputAttrs(x, snapshotExclude = TRUE)
8 }
9
10 #' Add a function for preprocessing an output before taking a test snapshot
11 #'
12 #' @param x A reactive which will be assigned to an output.
13 #' @param fun A function that takes the output value as an input and returns a
14 #' modified value. The returned value will be used for the test snapshot.
15 #'
16 #' @export
17 snapshotPreprocessOutput <- function(x, fun) {
18 markOutputAttrs(x, snapshotPreprocess = fun)
19 }
20
21
22 #' Add a function for preprocessing an input before taking a test snapshot
23 #'
24 #' @param inputId Name of the input value.
25 #' @param fun A function that takes the input value and returns a modified
26 #' value. The returned value will be used for the test snapshot.
27 #' @param session A Shiny session object.
28 #'
29 #' @export
30 snapshotPreprocessInput <- function(inputId, fun, session = getDefaultReactiveDomain()) {
31 if (is.null(session)) {
32 stop("snapshotPreprocessInput() needs a session object.")
33 }
34
35 input_impl <- .subset2(session$input, "impl")
36 input_impl$setMeta(inputId, "shiny.snapshot.preprocess", fun)
37 }
38
39
40 # Strip out file path from fileInput value
41 snapshotPreprocessorFileInput <- function(value) {
42 value$datapath <- basename(value$datapath)
43 value
44 }