diff --git a/R/server-input-handlers.R b/R/server-input-handlers.R index ac18c41e27..d55ee8286d 100644 --- a/R/server-input-handlers.R +++ b/R/server-input-handlers.R @@ -5,14 +5,15 @@ inputHandlers <- Map$new() #' #' Adds an input handler for data of this type. When called, Shiny will use the #' function provided to refine the data passed back from the client (after being -#' deserialized by jsonlite) before making it available in the `input` -#' variable of the `server.R` file. +#' deserialized by jsonlite) before making it available in the `input` variable +#' of the `server.R` file. #' #' This function will register the handler for the duration of the R process #' (unless Shiny is explicitly reloaded). For that reason, the `type` used #' should be very specific to this package to minimize the risk of colliding #' with another Shiny package which might use this data type name. We recommend -#' the format of "packageName.widgetName". +#' the format of "packageName.widgetName". It should be called from the +#' package's `.onLoad()` function. #' #' Currently Shiny registers the following handlers: `shiny.matrix`, #' `shiny.number`, and `shiny.date`. @@ -20,23 +21,20 @@ inputHandlers <- Map$new() #' The `type` of a custom Shiny Input widget will be deduced using the #' `getType()` JavaScript function on the registered Shiny inputBinding. #' @param type The type for which the handler should be added --- should be a -#' single-element character vector. +#' single-element character vector. #' @param fun The handler function. This is the function that will be used to #' parse the data delivered from the client before it is available in the #' `input` variable. The function will be called with the following three -#' parameters: -#' \enumerate{ -#' \item{The value of this input as provided by the client, deserialized -#' using jsonlite.} -#' \item{The `shinysession` in which the input exists.} -#' \item{The name of the input.} -#' } -#' @param force If `TRUE`, will overwrite any existing handler without -#' warning. If `FALSE`, will throw an error if this class already has -#' a handler defined. +#' parameters: \enumerate{ \item{The value of this input as provided by the +#' client, deserialized using jsonlite.} \item{The `shinysession` in which the +#' input exists.} \item{The name of the input.} } +#' @param force If `TRUE`, will overwrite any existing handler without warning. +#' If `FALSE`, will throw an error if this class already has a handler +#' defined. #' @examples #' \dontrun{ #' # Register an input handler which rounds a input number to the nearest integer +#' # In a package, this should be called from the .onLoad function. #' registerInputHandler("mypackage.validint", function(x, shinysession, name) { #' if (is.null(x)) return(NA) #' round(x) diff --git a/man/registerInputHandler.Rd b/man/registerInputHandler.Rd index 46a44a90fb..7e506be914 100644 --- a/man/registerInputHandler.Rd +++ b/man/registerInputHandler.Rd @@ -13,30 +13,27 @@ single-element character vector.} \item{fun}{The handler function. This is the function that will be used to parse the data delivered from the client before it is available in the \code{input} variable. The function will be called with the following three -parameters: -\enumerate{ -\item{The value of this input as provided by the client, deserialized -using jsonlite.} -\item{The \code{shinysession} in which the input exists.} -\item{The name of the input.} -}} +parameters: \enumerate{ \item{The value of this input as provided by the +client, deserialized using jsonlite.} \item{The \code{shinysession} in which the +input exists.} \item{The name of the input.} }} -\item{force}{If \code{TRUE}, will overwrite any existing handler without -warning. If \code{FALSE}, will throw an error if this class already has -a handler defined.} +\item{force}{If \code{TRUE}, will overwrite any existing handler without warning. +If \code{FALSE}, will throw an error if this class already has a handler +defined.} } \description{ Adds an input handler for data of this type. When called, Shiny will use the function provided to refine the data passed back from the client (after being -deserialized by jsonlite) before making it available in the \code{input} -variable of the \code{server.R} file. +deserialized by jsonlite) before making it available in the \code{input} variable +of the \code{server.R} file. } \details{ This function will register the handler for the duration of the R process (unless Shiny is explicitly reloaded). For that reason, the \code{type} used should be very specific to this package to minimize the risk of colliding with another Shiny package which might use this data type name. We recommend -the format of "packageName.widgetName". +the format of "packageName.widgetName". It should be called from the +package's \code{.onLoad()} function. Currently Shiny registers the following handlers: \code{shiny.matrix}, \code{shiny.number}, and \code{shiny.date}. @@ -47,6 +44,7 @@ The \code{type} of a custom Shiny Input widget will be deduced using the \examples{ \dontrun{ # Register an input handler which rounds a input number to the nearest integer +# In a package, this should be called from the .onLoad function. registerInputHandler("mypackage.validint", function(x, shinysession, name) { if (is.null(x)) return(NA) round(x)