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.
inputHandler(
create.ui = function(x, ns = identity, value = NULL) { tags$div(id =
session$ns(x$id)) },
default.value = "",
params.list = list(),
update.ui = function(x, session) { },
get.input = function(x, session) { return(list(session$input[[x$id]])) },
set.input = function(x, session, value) { update.ui(x, session, value) },
as.value = function(x, session = NULL, value = NULL) { if (is.null(value))
value <- getHandler(x)$get.input(x, session)[[1]] 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) { }
)
| create.ui | function used to create the input UI. |
|---|---|
| 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: |
| update.ui | function used to update the input UI. |
| get.input | function that returns the raw input(s) from the |
| as.value | function that transforms the value from |
| as.source | function that transforms the value from |
| observer | actions to be taken as an observer of any reactive expression(s). |
the list of functions to handle the the input type.
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.