File: onLoad.R

package info (click to toggle)
r-cran-bslib 0.9.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,412 kB
  • sloc: javascript: 13,349; makefile: 33; sh: 23
file content (36 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
.onLoad <- function(libname, pkgname) {
  register_upgrade_message("shiny", "1.6.0")
  register_upgrade_message("rmarkdown", "2.7")
  .dependency_cache <<- cachem::cache_mem(max_age = 1)

  # Call setup_input_handlers() when both bslib and shiny are loaded
  if (!setup_input_handlers()) {
    # shiny is not yet loaded, if it ever gets loaded we'll register then
    setHook(packageEvent("shiny", "onLoad"), function(...) {
      setup_input_handlers()
    })
  }
}

.dependency_cache <- NULL

# Returns TRUE if input handlers were successfully loaded
setup_input_handlers <- function() {
  if (!"shiny" %in% loadedNamespaces()) {
    return(FALSE)
  }

  if (!"registerInputHandler" %in% names(asNamespace("shiny"))) {
    # In devtools::load_all(), the shiny namespace is loaded but empty at the
    # time bslib loads. It's OK not to do the registration now, it'll just
    # happen when shiny finishes loading.
    return(FALSE)
  }

  shiny::registerInputHandler(
    "bslib.taskbutton",
    input_task_button_input_handler,
    force = TRUE
  )
  TRUE
}