Merge pull request #424 from rstudio/bugfix/zero-arg-sourcerefs

Handle zero-argument outputs gracefully
This commit is contained in:
Winston Chang
2014-03-27 12:48:41 -05:00
2 changed files with 12 additions and 2 deletions

View File

@@ -602,8 +602,16 @@ ShinySession <- setRefClass(
#' @export
`$<-.shinyoutput` <- function(x, name, value) {
label <- deparse(substitute(value))
attr(label, "srcref") <- srcrefFromShinyCall(substitute(value)[[2]])
attr(label, "srcfile") <- srcFileOfRef(attr(substitute(value)[[2]], "srcref")[[1]])
if (length(substitute(value)) > 1) {
# value is an object consisting of a call and its arguments. Here we want
# to find the source references for the first argument (if there are
# arguments), which generally corresponds to the reactive expression--
# e.g. in renderTable({ x }), { x } is the expression to trace.
attr(label, "srcref") <- srcrefFromShinyCall(substitute(value)[[2]])
srcref <- attr(substitute(value)[[2]], "srcref")
if (length(srcref) > 0)
attr(label, "srcfile") <- srcFileOfRef(srcref[[1]])
}
.subset2(x, 'impl')$defineOutput(name, value, label)
return(invisible(x))
}

View File

@@ -488,6 +488,8 @@ checkAsIs <- function(options) {
srcrefFromShinyCall <- function(expr) {
srcrefs <- attr(expr, "srcref")
num_exprs <- length(srcrefs)
if (num_exprs < 1)
return(NULL)
c(srcrefs[[1]][1], srcrefs[[1]][2],
srcrefs[[num_exprs]][3], srcrefs[[num_exprs]][4],
srcrefs[[1]][5], srcrefs[[num_exprs]][6])