Adding Javascript file to run and pass parms to function

I have a js file calling from Shiny, and looking to pass a parm to that function based on Shiny App activity. Suggestions? I can't find anywhere showing the documented. thank you

ui <- fluidPage(
  user_to_say_hello_to <- 'jonny'
  tags$script(src = "hello_world.js", user_to_say_hello_to) # doesn't work
  #tags$script(src = "hello_world.js") runs but want to pass parm

And my js file located in www directory:

function hello_world(name) { 
  message_string = "hello " + name;

This is quite easily done using custom message handlers. It is quite well described in the below article:

Great, thats helps! Possible to send multiple args? I tried c(arg1, arg2) but no avail.

The arguments are automatically converted to JSON format. To send multiple arguments you could for instance try:

message <- list(arg1 = val1, arg2 =val2)

session$sendCustomMessage(type, message)

you can then access the values in JS using :

message.arg1 or message.arg2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.