inputHandler: Define behaviour of an input type

Description Usage Arguments Details Value

View source: R/input_handlers.R

Description

This function prepares a structure that defines all aspects of an input type: UI creation, UI updating, observer function and string representation of the input value.

Usage

 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
inputHandler(
  default.value = "",
  params.list = list(),
  initInput = function(x) {     x },
  createUI = function(x, ns = identity, value = NULL) {     tags$div(id =
    session$ns(x$id)) },
  updateUI = function(x, session) { },
  setState = function(x, session, enabled, return.js = FALSE) {     if (class(x) ==
    "character")          id <- x     else id <- x$id     selector <- paste0("$(\"#",
    session$ns(id), "\")")     js <- paste0(selector, ".attr(\"disabled\",",
    jsBoolean(!enabled), ")") %>% print     if (return.js)          return(js)     else
    shinyjs::runjs(js) },
  setVisible = function(x, session, visible, tag.only = FALSE, return.js = FALSE) {    
    if (class(x) == "character")          id <- x     else id <- x$id     action <- if
    (visible)          "removeClass(\"d-none\")"     else "addClass(\"d-none\")"    
    if (tag.only)          selector <- paste0("$(\"#", session$ns(id), "\")")     else
    selector <- paste0("$(\"#", session$ns(id), "\").parent()")     js <-
    paste0(selector, ".", action, ";")     if (return.js)          return(js)     else
    shinyjs::runjs(js) },
  get.input = function(x, session) {     return(session$input[[x$id]]) },
  set.input = function(x, session, value) {     updateUI(x, session, value) },
  as.value = function(x, session = NULL, value = NULL) {     if (is.null(value))       
      value <- getHandler(x)$get.input(x, session)     value <- as.character(value)    
    if (length(value) > 1)          stop("input must have length 1.")     return(value) },
  as.string = function(x, session, value = NULL) {     getHandler(x)$as.value(x,
    session, value) %>% toString },
  as.source = function(x, session = NULL, value = NULL) {     getHandler(x)$as.value(x,
    session, value) %>% as.character },
  observer = function(x, session) { }
)

Arguments

default.value

default value of this input type

params.list

list of parameters used by the input type. Each element of the list describes a parameter and has the following members: name (pretty name of the parameter), type (one of character, numeric, logical, choices), choices (when type is choices, the vector of allowed values), default (default value).

createUI

function used to create the input UI.

updateUI

function used to update the input UI.

get.input

function that returns the raw input(s) from the session$input object as a list.

as.value

function that transforms the value from get.input() to the appropriate format for the input type. If value is provided, then the function tries to coerce this value to the appropriate type.

as.source

function that transforms the value from as.value() to source code.

observer

actions to be taken as an observer of any reactive expression(s).

Details

The default functions assume a single input and return the value without transformations get.input() returns a list of one element, as.value unlists this element, and as.source() returns that value as a character value.

Value

the list of functions to handle the the input type.


amar00k/rslates documentation built on May 25, 2021, 1:12 p.m.