Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui authored Mar 28, 2024
2 parents e5e573b + 578f7cd commit 29c459f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGES IN DT VERSION 0.33

- Added `outputArgs` parameter to `renderDataTable`, to allow width and height to be set when using interactive R Markdown documents.

- Fixed a bug in `renderDT()`'s evaluation of `...` arguments when `quoted = TRUE` (#1130).

# CHANGES IN DT VERSION 0.32

Expand Down
31 changes: 23 additions & 8 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' functions in the \pkg{shiny} package. The former is used to create a
#' container for table, and the latter is used in the server logic to render the
#' table.
#' @inheritParams shiny::dataTableOutput
#' @param outputId output variable to read the table from
#' @param width the width of the table container
#' @param height the height of the table container
#' @param fill passed to \code{htmlwidgets::\link{shinyWidgetOutput}()}, see
Expand Down Expand Up @@ -42,7 +42,6 @@ DTOutput = dataTableOutput

#' @export
#' @rdname dataTableOutput
#' @inheritParams shiny::renderDataTable
#' @param expr an expression to create a table widget (normally via
#' \code{\link{datatable}()}), or a data object to be passed to
#' \code{datatable()} to create a table widget
Expand All @@ -53,17 +52,31 @@ DTOutput = dataTableOutput
#' browsers to slow down or crash. Note that if you want to use
#' \code{renderDataTable} with \code{shiny::bindCache()}, this must be
#' \code{FALSE}.
#' @param env The parent environment for the reactive expression. By default,
#' this is the calling environment, the same as when defining an ordinary
#' non-reactive expression. If \code{expr} is a quosure and \code{quoted} is
#' \code{TRUE}, then \code{env} is ignored.
#' @param quoted If it is \code{TRUE}, then the
#' \code{\link[substitute]{quote}()}ed value of \code{expr} will be used when
#' \code{expr} is evaluated. If \code{expr} is a quosure and you would like to
#' use its expression as a value for \code{expr}, then you must set
#' \code{quoted} to \code{TRUE}.
#' @param funcFilter (for expert use only) passed to the \code{filter} argument
#' of \code{\link{dataTableAjax}()}
#' @param future whether the server-side filter function should be executed
#' as a future or as a standard synchronous function. If true, the future
#' will be evaluated according to the session's \link[future]{plan}.
#' @param outputArgs A list of arguments to be passed through to the implicit
#' call to \code{\link{dataTableOutput}()} when
#' \code{\link{renderDataTable}()} is used in an interactive R Markdown
#' document.
#' @param ... ignored when \code{expr} returns a table widget, and passed as
#' additional arguments to \code{\link{datatable}()} when \code{expr} returns
#' a data object
renderDataTable = function(
expr, server = TRUE, env = parent.frame(), quoted = FALSE,
funcFilter = dataTablesFilter, future = FALSE, ...
funcFilter = dataTablesFilter, future = FALSE,
outputArgs = list(), ...
) {
if (!quoted) expr = substitute(expr)

Expand All @@ -86,7 +99,7 @@ renderDataTable = function(
outputInfoEnv[["session"]] = NULL

exprFunc = shiny::exprToFunction(expr, env, quoted = TRUE)
argFunc = shiny::exprToFunction(list(..., server = server), env, quoted = FALSE)
argFunc = shiny::exprToFunction(list(..., server = server), parent.frame(), quoted = FALSE)
widgetFunc = function() {
opts = options(DT.datatable.shiny = TRUE); on.exit(options(opts), add = TRUE)
instance = exprFunc()
Expand Down Expand Up @@ -169,9 +182,10 @@ renderDataTable = function(
uiFunc = dataTableOutput,
renderFunc = function(shinysession, name, ...) {
domain = tempVarsPromiseDomain(outputInfoEnv, outputName = name, session = shinysession)
removeTimestampFromSnapshot(name)
removeTimestampFromSnapshot(name, shinysession)
promises::with_promise_domain(domain, renderFunc())
},
outputArgs = outputArgs,
cacheHint = cacheHint
)
} else {
Expand All @@ -181,7 +195,8 @@ renderDataTable = function(
domain = tempVarsPromiseDomain(outputInfoEnv, outputName = name, session = shinysession)
removeTimestampFromSnapshot(name)
promises::with_promise_domain(domain, renderFunc())
}
},
outputArgs = outputArgs
)
}

Expand Down Expand Up @@ -216,11 +231,11 @@ setAll = function(lst, env) {
invisible()
}

removeTimestampFromSnapshot = function(name) {
removeTimestampFromSnapshot = function(name, session) {
shiny::snapshotPreprocessInput(paste0(name, "_state"), function(value) {
value$time <- NULL
value
})
}, session)
}

# This promise domain is needed to set/unset temporary variables in
Expand Down
18 changes: 13 additions & 5 deletions man/dataTableOutput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 29c459f

Please sign in to comment.