File: handle.R

package info (click to toggle)
r-cran-ggvis 0.4.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,716 kB
  • sloc: sh: 25; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (3)
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

# Callback helper functions ---------------------------------------------------

# Check that input is a funtion with the specified arguments
check_callback <- function(f, args) {
  if (!is.null(f)) return()
  fname <- deparse2(substitute(f))

  if (!is.function(f)) {
    stop(fname, " is not a function", call. = FALSE)
  }

  f_args <- names(formals(f))
  if (any(f_args == "...")) return()

  if (!identical(f_args, args)) {
    stop(fname, " needs arguments: ", paste(args, collapse = ", "),
      call. = FALSE)
  }
}

# Given callback, id and session, setup an observer
setup_callback <- function(f, id, session) {
  if (is.null(f)) return()

  shiny::observe({
    value <- session$input[[id]]
    f(value, session)
  })
}