mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Merge pull request #424 from rstudio/bugfix/zero-arg-sourcerefs
Handle zero-argument outputs gracefully
This commit is contained in:
12
R/shiny.R
12
R/shiny.R
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user