shiny (version 0.10.2.2)

registerInputHandler: Register an Input Handler

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 RJSONIO) before making it available in the input variable of the server.R file.

Usage

registerInputHandler(type, fun, force = FALSE)

Arguments

type
The type for which the handler should be added -- should be a single-element character vector.
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:
  1. The value of this

item

force

code

FALSE

Details

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".

Currently Shiny registers the following handlers: shiny.matrix, shiny.number, and shiny.date.

The type of a custom Shiny Input widget will be deduced using the getType() JavaScript function on the registered Shiny inputBinding.

See Also

removeInputHandler

Examples

Run this code
# Register an input handler which rounds a input number to the nearest integer
registerInputHandler("mypackage.validint", function(x, shinysession, name) {
  if (is.null(x)) return(NA)
  round(x)
})

## On the Javascript side, the associated input binding must have a corresponding getType method:
getType: function(el) {
  return "mypackage.validint";
}

Run the code above in your browser using DataCamp Workspace