shiny.input_handler.input_handlers#

shiny.input_handler.input_handlers: shiny.input_handler._InputHandlers = {'shiny.action': <function _>, 'shiny.date': <function _>, 'shiny.datetime': <function _>, 'shiny.file': <function _>, 'shiny.number': <function _>, 'shiny.password': <function _>}#

Manage Shiny input handlers.

Add and/or remove input handlers of a given type. Shiny uses these handlers to pre-process input values from the client (after being deserialized) before passing them to the input argument of an App()’s server function.

The type is based on the getType() JavaScript method on the relevant Shiny input binding. See this article for more information on how to create custom input bindings.

shiny.input_handler.add(type: str, force: bool = False) Callable[[InputHandlerType], None]#

Register an input handler. This method returns a decorator that registers the decorated function as the handler for the given type. This handler should accept three arguments: - the input value - the input name - the Session object

shiny.input_handler.remove(type: str)#

Unregister an input handler.

Note

add() ing an input handler will make it persist for the duration of the Python process (unless Shiny is explicitly reloaded). For that reason, verbose naming is encouraged to minimize the risk of colliding with other Shiny input binding(s) which happen to use the same type (if this the binding is bundled with a package, we recommend the format of “packageName.widgetName”).

Example

from shiny.input_handler import input_handlers
@input_handlers.add("mypackage.intify")
def _(value, name, session):
    return int(value)

On the Javascript side, the associated input binding must have a corresponding getType method:

getType: function(el) {
  return "mypackage.intify";
}