Skip to contents

Create an anonymous JS function to monitor an event and bind it to a shiny input

Usage

js_callback(id, js = "", value, ..., asis = FALSE, .ns = ns_find())

Arguments

id

(chr) Automatically namespaced with ns if inside a module

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'});
};
value

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

...

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

asis

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

.ns

fun ns function. Typically found automatically.

Value

(chr) with javascript interpolated with glue arguments

Examples

js_callback("widget", "var myValue = e.someProperty;", "myValue")
#> Warning: Could not find ns function. Using `function(x) x`
#> (e) => {
#> console.log('widget event');
#> var myValue = e.someProperty;
#> Shiny.setInputValue('widget', myValue, {priority: 'event'});
#>                    };