Skip to content

Commit

Permalink
feat: Add reload helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilzyla committed Jan 30, 2024
1 parent 7d3662f commit eaa257e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions R/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit eaa257e

Please sign in to comment.