diff --git a/R/app.R b/R/app.R index 2f21832a..2aa1d1d2 100644 --- a/R/app.R +++ b/R/app.R @@ -35,24 +35,6 @@ configure_logger <- function() { } } -load_main_module <- function() { - # Silence "no visible binding" notes raised by `box::use()` on R CMD check. - app <- NULL - main <- NULL - box::use(app/main) - main -} - -as_top_level <- function(app_env) { - list( - # Wrap the UI in a function to support Shiny bookmarking. - ui = function(request) app_env$main$ui("app"), - server = fix_server_reloading(function(input, output) { - app_env$main$server("app") - }) - ) -} - fix_server_reloading <- function(server) { reparse(curly_wrap(server)) } @@ -124,6 +106,24 @@ with_head_tags <- function(ui) { } } +call_ui <- function(ui, request) { + if (!is.function(ui)) { + ui + } else if (length(formals(ui)) == 0) { + ui() + } else { + ui(request) + } +} + +call_server <- function(server, input, output, session) { + if ("session" %in% formalArgs(server)) { + server(input, output, session) + } else { + server(input, output) + } +} + #' Rhino application #' #' The entrypoint for a Rhino application. @@ -170,7 +170,6 @@ with_head_tags <- function(ui) { #' @export app <- function() { setup_box_path() - box::purge_cache() configure_logger() shiny::addResourcePath("static", fs::path_wd("app", "static")) @@ -185,17 +184,27 @@ app <- function() { server = main$server ) } else if (identical(entrypoint, "box_top_level")) { - main <- load_main_module() + app_env <- load_app() + ui <- function(request) { + call_ui(app_env$main$ui, request) + } + server <- function(input, output, session) { + call_server(app_env$main$server, input, output, session) + } shiny::shinyApp( - ui = with_head_tags(main$ui), - server = main$server + ui = with_head_tags(ui), + server = reparse(server) ) } else if (is.null(entrypoint)) { app_env <- load_app() - main <- as_top_level(app_env) + # Wrap the UI in a function to support Shiny bookmarking. + ui <- function(request) app_env$main$ui("app") + server <- function(input, output) { + app_env$main$server("app") + } shiny::shinyApp( - ui = with_head_tags(main$ui), - server = main$server + ui = with_head_tags(ui), + server = fix_server_reloading(server) ) } else { stop()