From 2ad15620c96550ad2979d1e4859e59dda4e0045f Mon Sep 17 00:00:00 2001 From: Michal Lauer Date: Mon, 8 Apr 2024 17:10:24 +0200 Subject: [PATCH] Moved function definition --- R/shiny.R | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/R/shiny.R b/R/shiny.R index 85fa6429..69d2183a 100644 --- a/R/shiny.R +++ b/R/shiny.R @@ -99,15 +99,7 @@ renderDataTable = function( exprFunc = shiny::exprToFunction(expr, env, quoted = TRUE) 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() - if (promises::is.promising(instance)) { - promises::then(instance, processWidget) - } else { - processWidget(instance) - } - } + processWidget = function(instance) { args = argFunc() server = args$server; args$server = NULL # the last element is `server` @@ -167,6 +159,16 @@ renderDataTable = function( instance } + widgetFunc = function() { + opts = options(DT.datatable.shiny = TRUE); on.exit(options(opts), add = TRUE) + instance = exprFunc() + if (promises::is.promising(instance)) { + promises::then(instance, processWidget) + } else { + processWidget(instance) + } + } + renderFunc = htmlwidgets::shinyRenderWidget( widgetFunc(), dataTableOutput, environment(), FALSE )