clientsideFunction | R Documentation |
Create a callback that updates the output by calling a clientside (JavaScript) function instead of an R function.
Note that it is also possible to specify JavaScript as a character string instead of passing clientsideFunction
.
In this case Dash will inline your JavaScript automatically, without needing to save a script inside assets
.
clientsideFunction(namespace, function_name)
namespace |
Character. Describes where the JavaScript function resides (Dash will look
for the function at |
function_name |
Character. Provides the name of the JavaScript function to call. |
With this signature, Dash's front-end will call window.my_clientside_library.my_function
with the current
values of the value
properties of the components my-input
and another-input
whenever those values change.
Include a JavaScript file by including it your assets/
folder. The file can be named anything but you'll need to
assign the function's namespace to the window
. For example, this file might look like:
window.my_clientside_library = { my_function: function(input_value_1, input_value_2) { return ( parseFloat(input_value_1, 10) + parseFloat(input_value_2, 10) ); } }
## Not run:
app$callback(
output('output-clientside', 'children'),
params=list(input('input', 'value')),
clientsideFunction(
namespace = 'my_clientside_library',
function_name = 'my_function'
)
)
# Passing JavaScript as a character string
app$callback(
output('output-clientside', 'children'),
params=list(input('input', 'value')),
"function (value) {
return 'Client says \"' + value + '\"';
}"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.