Skip to content

Commit 7eb2958

Browse files
committed
a few minor tweaks
1 parent 5dafdab commit 7eb2958

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

R/shinywrappers.R

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,44 @@ markRenderFunction <- function(uiFunc, renderFunc, outputArgs = list()) {
2525
# a mutable object that keeps track of whether `useRenderFunction` has been
2626
# executed (this usually only happens when rendering Shiny code snippets in
2727
# 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)
3030

3131
origRenderFunc <- renderFunc
3232
renderFunc <- function(...) {
3333
# if the user provided something through `outputArgs` BUT the
3434
# `useRenderFunction` was not executed, then outputArgs will be ignored,
3535
# 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()) {
3737
warning("Unused argument: outputArgs. The argument outputArgs is only ",
3838
"meant to be used when embedding snippets of Shiny code in an ",
3939
"R Markdown code chunk (using runtime: shiny). When running a ",
4040
"full Shiny app, please set the output arguments directly in ",
4141
"the corresponding output function of your UI code.")
4242
# 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(...)
4451
}
45-
if (is.null(formals(origRenderFunc))) origRenderFunc()
46-
else origRenderFunc(...)
4752
}
4853

4954
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)
5459
}
5560

5661
useRenderFunction <- function(renderFunc, inline = FALSE) {
5762
outputFunction <- attr(renderFunc, "outputFunc")
5863
outputArgs <- attr(renderFunc, "outputArgs")
59-
executed <- attr(renderFunc, "executed_useRenderFunction")
60-
executed$set(TRUE)
64+
hasExecuted <- attr(renderFunc, "hasExecuted")
65+
hasExecuted$set(TRUE)
6166

6267
for (arg in names(outputArgs)) {
6368
if (!arg %in% names(formals(outputFunction))) {
@@ -243,7 +248,7 @@ renderPrint <- function(expr, env = parent.frame(), quoted = FALSE,
243248
width = getOption('width'), outputArgs=list()) {
244249
installExprFunction(expr, "func", env, quoted)
245250

246-
renderFunc <- function() {
251+
renderFunc <- function(shinysession, name, ...) {
247252
op <- options(width = width)
248253
on.exit(options(op), add = TRUE)
249254
paste(utils::capture.output(func()), collapse = "\n")
@@ -284,7 +289,7 @@ renderText <- function(expr, env=parent.frame(), quoted=FALSE,
284289
outputArgs=list()) {
285290
installExprFunction(expr, "func", env, quoted)
286291

287-
renderFunc <- function() {
292+
renderFunc <- function(shinysession, name, ...) {
288293
value <- func()
289294
return(paste(utils::capture.output(cat(value)), collapse="\n"))
290295
}

R/utils.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,12 @@ wrapFunctionLabel <- function(func, name, ..stacktraceon = FALSE) {
12971297
}
12981298

12991299

1300-
# This is a very simple mutable object which only stores one boolean value
1301-
# (which we can set and get). Using this class is sometimes useful when
1302-
# communicating persistent changes across functions.
1303-
MutableObj <- R6Class("MutableObj",
1300+
# This is a very simple mutable object which only stores one value
1301+
# (which we can set and get). Using this class is sometimes useful
1302+
# when communicating persistent changes across functions.
1303+
Mutable <- R6Class("Mutable",
13041304
private = list(
1305-
value = NA
1305+
value = NULL
13061306
),
13071307
public = list(
13081308
set = function(value) { private$value <- value },

0 commit comments

Comments
 (0)