@@ -25,39 +25,44 @@ markRenderFunction <- function(uiFunc, renderFunc, outputArgs = list()) {
25
25
# a mutable object that keeps track of whether `useRenderFunction` has been
26
26
# executed (this usually only happens when rendering Shiny code snippets in
27
27
# an interactive R Markdown document); its initial value is FALSE
28
- executed_useRenderFunction <- MutableObj $ new()
29
- executed_useRenderFunction $ set(FALSE )
28
+ hasExecuted <- Mutable $ new()
29
+ hasExecuted $ set(FALSE )
30
30
31
31
origRenderFunc <- renderFunc
32
32
renderFunc <- function (... ) {
33
33
# if the user provided something through `outputArgs` BUT the
34
34
# `useRenderFunction` was not executed, then outputArgs will be ignored,
35
35
# so throw a warning to let user know the correct usage
36
- if (length(outputArgs ) != 0 && ! executed_useRenderFunction $ get()) {
36
+ if (length(outputArgs ) != 0 && ! hasExecuted $ get()) {
37
37
warning(" Unused argument: outputArgs. The argument outputArgs is only " ,
38
38
" meant to be used when embedding snippets of Shiny code in an " ,
39
39
" R Markdown code chunk (using runtime: shiny). When running a " ,
40
40
" full Shiny app, please set the output arguments directly in " ,
41
41
" the corresponding output function of your UI code." )
42
42
# stop warning from happening again for the same object
43
- executed_useRenderFunction $ set(TRUE )
43
+ hasExecuted $ set(TRUE )
44
+ }
45
+ if (is.null(formals(origRenderFunc ))) {
46
+ warning(" The render function should take at least two arguments (`name` " ,
47
+ " and `shinysession`." )
48
+ origRenderFunc()
49
+ } else {
50
+ origRenderFunc(... )
44
51
}
45
- if (is.null(formals(origRenderFunc ))) origRenderFunc()
46
- else origRenderFunc(... )
47
52
}
48
53
49
54
structure(renderFunc ,
50
- class = c(" shiny.render.function" , " function" ),
51
- outputFunc = uiFunc ,
52
- outputArgs = outputArgs ,
53
- executed_useRenderFunction = executed_useRenderFunction )
55
+ class = c(" shiny.render.function" , " function" ),
56
+ outputFunc = uiFunc ,
57
+ outputArgs = outputArgs ,
58
+ hasExecuted = hasExecuted )
54
59
}
55
60
56
61
useRenderFunction <- function (renderFunc , inline = FALSE ) {
57
62
outputFunction <- attr(renderFunc , " outputFunc" )
58
63
outputArgs <- attr(renderFunc , " outputArgs" )
59
- executed <- attr(renderFunc , " executed_useRenderFunction " )
60
- executed $ set(TRUE )
64
+ hasExecuted <- attr(renderFunc , " hasExecuted " )
65
+ hasExecuted $ set(TRUE )
61
66
62
67
for (arg in names(outputArgs )) {
63
68
if (! arg %in% names(formals(outputFunction ))) {
@@ -243,7 +248,7 @@ renderPrint <- function(expr, env = parent.frame(), quoted = FALSE,
243
248
width = getOption(' width' ), outputArgs = list ()) {
244
249
installExprFunction(expr , " func" , env , quoted )
245
250
246
- renderFunc <- function () {
251
+ renderFunc <- function (shinysession , name , ... ) {
247
252
op <- options(width = width )
248
253
on.exit(options(op ), add = TRUE )
249
254
paste(utils :: capture.output(func()), collapse = " \n " )
@@ -284,7 +289,7 @@ renderText <- function(expr, env=parent.frame(), quoted=FALSE,
284
289
outputArgs = list ()) {
285
290
installExprFunction(expr , " func" , env , quoted )
286
291
287
- renderFunc <- function () {
292
+ renderFunc <- function (shinysession , name , ... ) {
288
293
value <- func()
289
294
return (paste(utils :: capture.output(cat(value )), collapse = " \n " ))
290
295
}
0 commit comments