Skip to contents

Create a javascript callback that runs when shiny connects.

Usage

js_set_input_val(
  id,
  value,
  js = NULL,
  ...,
  value_to = c("code", "chr", "json")[1],
  asis = FALSE,
  as_callback = FALSE,
  on = NULL,
  as_tag = FALSE,
  .ns = ns_find()
)

Arguments

id

(chr) Automatically namespaced with ns if inside a module

value

(js) arbitrary js code that defines the value to bind. Can also be a variable name if declared in the js argument

js

(chr) path to js file with just the anonymous function, or js code to interpolate into a generalized anonymous javascript function that uses glue insertions demarcated by {{}}:


(e) => {
         console.log('{{input}} event');
         {{js}}
Shiny.setInputValue('{{input}}', {{value}}, {priority: 'event'});
};
...

(additional named arguments) corresponding to any arguments that need be interpolated with glue

value_to

chr One of:

  • code The object will be treated as raw javascript code Default

  • chr The object will be treated as as JS character string

  • json The object will be coerced with toJSON

asis

If TRUE, use the ID as-is even when inside a module (instead of adding the namespace prefix to the ID).

as_callback

lgl Should the resulting code be wrapped in a callback function?

on

chr A javascript event name, must be specified with a selector to argument on_dom that indicates the jQuery selector for a DOM element to which the event will pertain.

as_tag

lgl Whether the output should be a script tag.

.ns

fun ns function. Typically found automatically.

add_tag

lgl whether to enclose in a script tag

Value

chr/shiny.tag script tag with javascript