Skip to content

Commit

Permalink
Moved function definition
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLauer committed Apr 8, 2024
1 parent 4e63a46 commit 2ad1562
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 2ad1562

Please sign in to comment.