
Last chance! 50% off unlimited learning
Sale ends in
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)
Character. Describes where the JavaScript function resides (Dash will look
for the function at window[namespace][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 + '\"';
}"
)
# }
Run the code above in your browser using DataLab