setInput {shiny.react} | R Documentation |
Set input
Description
Creates a handler which can be used for onChange
and similar
props of 'React' components to set the value of a 'Shiny' input to one of
the arguments passed to the handler.
Usage
setInput(inputId, jsAccessor)
## S4 method for signature 'character,missing'
setInput(inputId)
## S4 method for signature 'character,numeric'
setInput(inputId, jsAccessor)
## S4 method for signature 'character,character'
setInput(inputId, jsAccessor)
Arguments
inputId |
'Shiny' input ID to set the value on. |
jsAccessor |
Index (numeric 0-based index) or accessor (JavaScript string) of the argument to use as value. |
Details
The argument jsAccessor
can be empty (assumes jsAccessor = 0
) or
take one of the following types:
A valid JavaScript accessor string to be applied to the object (example:
jsAccessor = "[0].target.checked"
).A valid JavaScript 0-based index.
As an example, calling setInput("some_index", 1)
is equivalent to
setInput("some_index", "[1]")
Value
A ReactData
object which can be passed as a prop to 'React'
components.
Methods (by class)
-
setInput(inputId = character, jsAccessor = missing)
: Uses as indexjsAccessor = 0
-
setInput(inputId = character, jsAccessor = numeric)
: Gets the value via index (see examples). -
setInput(inputId = character, jsAccessor = character)
: Gets value via accessor (see examples).
Examples
# Same as `setInput("some_id", 0)`.
setInput("some_id")
# Equivalent to `(...args) => Shiny.setInputValue('some_id', args[1])` in JS.
setInput("some_id", 1)
# Same as `setInput("some_id", 1)`.
setInput("some_id", "[1]")
# Equivalent to `(...args) => Shiny.setInputValue('some_id', args[0].target.value)` in JS.
setInput("some_id", "[0].target.value")