|
69 | 69 | #' @export
|
70 | 70 | Progress <- R6Class(
|
71 | 71 | 'Progress',
|
72 |
| - portable = FALSE, |
| 72 | + portable = TRUE, |
73 | 73 | public = list(
|
74 |
| - .session = 'environment', |
75 |
| - .id = 'character', |
76 |
| - .min = 'numeric', |
77 |
| - .max = 'numeric', |
78 |
| - .value = 'ANY', |
79 |
| - .closed = 'logical', |
80 | 74 |
|
81 | 75 | initialize = function(session = getDefaultReactiveDomain(), min = 0, max = 1) {
|
82 | 76 | # A hacky check to make sure the session object is indeed a session object.
|
83 | 77 | if (is.null(session$onFlush)) stop("'session' is not a session object.")
|
84 | 78 |
|
85 |
| - .closed <<- FALSE |
86 |
| - .session <<- session |
87 |
| - .id <<- paste(as.character(as.raw(runif(8, min=0, max=255))), collapse='') |
88 |
| - .min <<- min |
89 |
| - .max <<- max |
90 |
| - .value <<- NULL |
| 79 | + private$session <- session |
| 80 | + private$id <- paste(as.character(as.raw(runif(8, min=0, max=255))), collapse='') |
| 81 | + private$min <- min |
| 82 | + private$max <- max |
| 83 | + private$value <- NULL |
| 84 | + private$closed <- FALSE |
91 | 85 |
|
92 |
| - .session$sendProgress('open', list(id = .id)) |
| 86 | + session$sendProgress('open', list(id = private$id)) |
93 | 87 | },
|
| 88 | + |
94 | 89 | set = function(message = NULL, detail = NULL, value = NULL) {
|
95 |
| - if (.closed) { |
| 90 | + if (private$closed) { |
96 | 91 | warning("Attempting to set progress, but progress already closed.")
|
97 | 92 | return()
|
98 | 93 | }
|
99 | 94 |
|
100 | 95 | if (is.null(value) || is.na(value)) {
|
101 | 96 | value <- NULL
|
102 | 97 | } else {
|
103 |
| - value <- min(1, max(0, (value - .min) / (.max - .min))) |
| 98 | + value <- min(1, max(0, (value - private$min) / (private$max - private$min))) |
104 | 99 | }
|
105 | 100 |
|
106 |
| - .value <<- value |
| 101 | + private$value <- value |
107 | 102 |
|
108 | 103 | data <- dropNulls(list(
|
109 |
| - id = .id, |
| 104 | + id = private$id, |
110 | 105 | message = message,
|
111 | 106 | detail = detail,
|
112 | 107 | value = value
|
113 | 108 | ))
|
114 | 109 |
|
115 |
| - .session$sendProgress('update', data) |
| 110 | + private$session$sendProgress('update', data) |
116 | 111 | },
|
117 |
| - getMin = function() .min, |
118 |
| - getMax = function() .max, |
119 |
| - getValue = function() .value, |
| 112 | + |
| 113 | + getMin = function() private$min, |
| 114 | + |
| 115 | + getMax = function() private$max, |
| 116 | + |
| 117 | + getValue = function() private$value, |
| 118 | + |
120 | 119 | close = function() {
|
121 |
| - if (.closed) { |
| 120 | + if (private$closed) { |
122 | 121 | warning("Attempting to close progress, but progress already closed.")
|
123 | 122 | return()
|
124 | 123 | }
|
125 | 124 |
|
126 |
| - .session$sendProgress('close', list(id = .id)) |
127 |
| - .closed <<- TRUE |
| 125 | + private$session$sendProgress('close', list(id = private$id)) |
| 126 | + private$closed <- TRUE |
128 | 127 | }
|
| 128 | + ), |
| 129 | + |
| 130 | + private = list( |
| 131 | + session = 'environment', |
| 132 | + id = character(0), |
| 133 | + min = numeric(0), |
| 134 | + max = numeric(0), |
| 135 | + value = NULL, |
| 136 | + closed = logical(0) |
129 | 137 | )
|
130 | 138 | )
|
131 | 139 |
|
|
0 commit comments