Description Usage Arguments Details Value
View source: R/input_handlers.R
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.
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) { }
)
|
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: |
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 |
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 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.
the list of functions to handle the the input type.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.