File: utils-shiny.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 (58 lines) | stat: -rw-r--r-- 1,469 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
get_current_session <- function(
  require_active = TRUE,
  call = rlang::caller_env()
) {
  session <- if (isNamespaceLoaded("shiny")) {
    shiny::getDefaultReactiveDomain()
  }

  if (is.null(session) && require_active) {
    rlang::abort(
      paste(
        "This function must be called with a Shiny `server` function",
        "(i.e., it can only be used inside an active user session)."
      ),
      call = call,
      class = "shiny-no-active-session"
    )
  }

  session
}

has_valid_reactive_context <- function(session) {
  if (is.null(session)) return(FALSE)
  if (!"getCurrentTheme" %in% names(session)) return(FALSE)
  hasReactiveContext <- getFromNamespace("hasCurrentContext", "shiny") %||%
    function() FALSE
  hasReactiveContext()
}

get_current_theme <- function() {
  if (isNamespaceLoaded("shiny")) shiny::getCurrentTheme()
}

# Shiny internal funcs needed for nav_panel() (i.e., tabPanel()) logic

processDeps <- function(...) {
  getFromNamespace("processDeps", "shiny")(...)
}

p_randomInt <- function(...) {
  getFromNamespace("p_randomInt", "shiny")(...)
}

# Copy of shiny::getCurrentThemeVersion()
# (copied to avoid >1.6.0 dependency)
getCurrentThemeVersion <- function() {
  theme <- shiny::getCurrentTheme()
  if (is_bs_theme(theme)) theme_version(theme) else "3"
}

# Copy of shiny:::anyNamed()
anyNamed <- function(x) {
  if (length(x) == 0) return(FALSE)
  nms <- names(x)
  if (is.null(nms)) return(FALSE)
  any(nzchar(nms))
}