From eaa257eb90366fbd7934022c976722e4b425c7f3 Mon Sep 17 00:00:00 2001 From: Kamil Zyla Date: Tue, 30 Jan 2024 10:17:23 +0100 Subject: [PATCH] feat: Add reload helper functions --- R/app.R | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/R/app.R b/R/app.R index a7b19d55..74b232d8 100644 --- a/R/app.R +++ b/R/app.R @@ -55,6 +55,41 @@ as_top_level <- function(shiny_module) { wrap(shiny_module) } +load_app <- function() { + # Silence "no visible binding" notes raised by `box::use()` on R CMD check. + app <- NULL + main <- NULL + + app_env <- new.env(parent = baseenv()) + load_main <- function() { + box::purge_cache() + local(box::use(app/main), app_env) + } + + load_main() + register_reload_callback(load_main) + + app_env +} + +clear_reload_callback <- function() NULL + +register_reload_callback <- function(callback) { + message("@ Clearing reload callback") + clear_reload_callback() + + message("@ Registering reload callback") + clear_reload_callback <<- shiny:::autoReloadCallbacks$register( + function() { + message("@ Reload callback") + tryCatch( + callback(), + error = function(cond) message(conditionMessage(cond)) + ) + } + ) +} + with_head_tags <- function(ui) { wrap <- function(tag) { shiny::tagList(