Skip to contents

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 character,missing
setInput(inputId)

# S4 method for character,numeric
setInput(inputId, jsAccessor)

# S4 method for 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.

Value

A ReactData object which can be passed as a prop to 'React' components.

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]")

Methods (by class)

  • setInput(inputId = character, jsAccessor = missing): Uses as index jsAccessor = 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")
#> $type
#> [1] "input"
#> 
#> $id
#> [1] "some_id"
#> 
#> $jsAccessor
#> [1] "[0]"
#> 
#> attr(,"class")
#> [1] "ReactData" "list"     

# Equivalent to `(...args) => Shiny.setInputValue('some_id', args[1])` in JS.
setInput("some_id", 1)
#> $type
#> [1] "input"
#> 
#> $id
#> [1] "some_id"
#> 
#> $jsAccessor
#> [1] "[1]"
#> 
#> attr(,"class")
#> [1] "ReactData" "list"     

# Same as `setInput("some_id", 1)`.
setInput("some_id", "[1]")
#> $type
#> [1] "input"
#> 
#> $id
#> [1] "some_id"
#> 
#> $jsAccessor
#> [1] "[1]"
#> 
#> attr(,"class")
#> [1] "ReactData" "list"     

# Equivalent to `(...args) => Shiny.setInputValue('some_id', args[0].target.value)` in JS.
setInput("some_id", "[0].target.value")
#> $type
#> [1] "input"
#> 
#> $id
#> [1] "some_id"
#> 
#> $jsAccessor
#> [1] "[0].target.value"
#> 
#> attr(,"class")
#> [1] "ReactData" "list"