/
progress.R
164 lines (139 loc) · 3.92 KB
/
progress.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#' Report Progress Waitress
#'
#' Report progress with waitress.
#'
#' @param ... Passed to the Waitress constructor (`Waitress$new()`).
#' @param expr The work to be done.
#' This expression should contain calls to
#' setProgressWaitress` or `incProgressWaitress`.
#' @param session The Shiny session object, as provided by
#' `shinyServer` to the server function. The default is to
#' automatically find the session by using the current
#' reactive domain.
#' @param env The environment in which `expr` should be evaluated.
#' @param quoted Whether `expr` is a quoted expression
#' (this is not common).
#' @param value Value to set the waitress to or increase it by.
#'
#' @name withProgressWaitress
#' @export
withProgressWaitress <- function(
expr,
...,
session = getDefaultReactiveDomain(),
env = parent.frame(),
quoted = FALSE
){
if(!quoted)
expr <- substitute(expr)
if(is.null(session$progressStack))
stop("'session' is not a ShinySession object.")
p <- Waitress$new(...)
session$progressStack$push(p)
on.exit({
session$progressStack$pop()
p$close()
})
eval(expr, env)
}
#' @rdname withProgressWaitress
#' @export
setProgressWaitress <- function(
value = 1,
session = getDefaultReactiveDomain()
){
if(is.null(session$progressStack))
stop("'session' is not a ShinySession object.")
if(session$progressStack$size() == 0){
warning('setProgress was called outside of withProgress; ignoring')
return()
}
session$progressStack$peek()$set(value)
invisible()
}
#' @rdname withProgressWaitress
#' @export
incProgressWaitress <- function(
value = 1,
session = getDefaultReactiveDomain()
){
if(is.null(session$progressStack))
stop("'session' is not a ShinySession object.")
if(session$progressStack$size() == 0){
warning('incProgress was called outside of withProgress; ignoring')
return()
}
session$progressStack$peek()$inc(value)
invisible()
}
#' Report Progress Attendant
#'
#' Report progress with attendant.
#'
#' @param ... Passed to the Attendant constructor (`Attendant$new()`).
#' @param expr The work to be done.
#' This expression should contain calls to
#' setProgressAttendant` or `incProgressAttendant`.
#' @param session The Shiny session object, as provided by
#' `shinyServer` to the server function. The default is to
#' automatically find the session by using the current
#' reactive domain.
#' @param env The environment in which `expr` should be evaluated.
#' @param quoted Whether `expr` is a quoted expression
#' (this is not common).
#' @param value Value to set the waitress to or increase it by.
#' @param text Text to display on the progress bar.
#'
#' @name withProgressAttendant
#' @export
withProgressAttendant <- function(
expr,
...,
session = getDefaultReactiveDomain(),
env = parent.frame(),
quoted = FALSE
){
if(!quoted)
expr <- substitute(expr)
if(is.null(session$progressStack))
stop("'session' is not a ShinySession object.")
p <- Attendant$new(...)
session$progressStack$push(p)
on.exit({
session$progressStack$pop()
p$close()
})
eval(expr, env)
}
#' @rdname withProgressAttendant
#' @export
setProgressAttendant <- function(
value = 1,
text = NULL,
session = getDefaultReactiveDomain()
){
if(is.null(session$progressStack))
stop("'session' is not a ShinySession object.")
if(session$progressStack$size() == 0){
warning('setProgress was called outside of withProgress; ignoring')
return()
}
session$progressStack$peek()$set(value, text)
invisible()
}
#' @rdname withProgressAttendant
#' @export
incProgressAttendant <- function(
value = 1,
text = NULL,
session = getDefaultReactiveDomain()
){
if(is.null(session$progressStack))
stop("'session' is not a ShinySession object.")
if(session$progressStack$size() == 0){
warning('incProgress was called outside of withProgress; ignoring')
return()
}
session$progressStack$peek()$inc(value, text)
invisible()
}