Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upregisterInputHandler support, redux #28
Conversation
|
@alandipert great work, thanks! This will be very nice to have for custom situations, which I think will be more common with |
This is a second attempt at adding support for
shiny::registerInputHandler(). In my first attempt, I didn't understand the purpose ofgetType(). Now, I understand that an input's type is a namespace distinct from the name argument ofShiny.inputBindings.register()and with a different extent. Using an input's name as its type, as I did in #26, made no sense.An input's name is used to alter the priority of an input in the event of a DOM conflict, and there is a 1-1 correspondence between an input and its name.
An input's type, on the other hand, has a different purpose. In R,
shiny::registerInputHandler()is used to associate a type with an input handler that will coerce an input's value with a a matching type from a JSON representation to some alternate R representation.So, every input has one and only one name, and also (optionally) a type, but multiple inputs may share a type.
To implement this, I added a new property to the
optionsargument ofreactR.reactShinyInput():type.typemay be a function, used as the input'sgetType()implementation. For expedience,typemay also befalseor a type name string, which is probably the most common use case.I updated https://github.com/react-R/colorpicker-example to demonstrate usage of the functionality in this PR.