Debian Codegraph @

man/registerInputHandler.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/server-input-handlers.R
3 \name{registerInputHandler}
4 \alias{registerInputHandler}
5 \title{Register an Input Handler}
6 \usage{
7 registerInputHandler(type, fun, force = FALSE)
8 }
9 \arguments{
10 \item{type}{The type for which the handler should be added --- should be a
11 single-element character vector.}
12
13 \item{fun}{The handler function. This is the function that will be used to
14 parse the data delivered from the client before it is available in the
15 \code{input} variable. The function will be called with the following three
16 parameters: \enumerate{ \item{The value of this input as provided by the
17 client, deserialized using jsonlite.} \item{The \code{shinysession} in which the
18 input exists.} \item{The name of the input.} }}
19
20 \item{force}{If \code{TRUE}, will overwrite any existing handler without warning.
21 If \code{FALSE}, will throw an error if this class already has a handler
22 defined.}
23 }
24 \description{
25 Adds an input handler for data of this type. When called, Shiny will use the
26 function provided to refine the data passed back from the client (after being
27 deserialized by jsonlite) before making it available in the \code{input} variable
28 of the \code{server.R} file.
29 }
30 \details{
31 This function will register the handler for the duration of the R process
32 (unless Shiny is explicitly reloaded). For that reason, the \code{type} used
33 should be very specific to this package to minimize the risk of colliding
34 with another Shiny package which might use this data type name. We recommend
35 the format of "packageName.widgetName". It should be called from the
36 package's \code{.onLoad()} function.
37
38 Currently Shiny registers the following handlers: \code{shiny.matrix},
39 \code{shiny.number}, and \code{shiny.date}.
40
41 The \code{type} of a custom Shiny Input widget will be deduced using the
42 \code{getType()} JavaScript function on the registered Shiny inputBinding.
43 }
44 \examples{
45 \dontrun{
46 # Register an input handler which rounds a input number to the nearest integer
47 # In a package, this should be called from the .onLoad function.
48 registerInputHandler("mypackage.validint", function(x, shinysession, name) {
49 if (is.null(x)) return(NA)
50 round(x)
51 })
52
53 ## On the Javascript side, the associated input binding must have a corresponding getType method:
54 # getType: function(el) {
55 # return "mypackage.validint";
56 # }
57
58 }
59 }
60 \seealso{
61 \code{\link[=removeInputHandler]{removeInputHandler()}} \code{\link[=applyInputHandlers]{applyInputHandlers()}}
62 }