If I use the session$sendCustomMessage
command in my server file and input a list of three things, how do I access the three different things in my message-handler.js
file?
Say my call looks like this:
session$sendCustomMessage(type='testmessage', message=list(pid=pid, cid=cid, query=sql))
In my .js file I want to use pid, cid and query seperately, any ideas on how I do that?
Thanks!!
You would access them as message.pid, message.cid
etc. The list is passed as JSON
. An example adapted from http://shiny.rstudio.com/gallery/server-to-client-custom-messages.html:
library(shiny)
runApp(
list(ui = fluidPage(
titlePanel("sendCustomMessage example"),
fluidRow(
column(4, wellPanel(
sliderInput("controller", "Controller:",
min = 1, max = 20, value = 15),
singleton(
tags$head(tags$script('Shiny.addCustomMessageHandler("testmessage",
function(message) {
alert("The b variable is " + message.b);
}
);'))
)
))
)
)
, server = function(input, output, session){
observe({
session$sendCustomMessage(type = 'testmessage',
message = list(a = 1, b = 'text',
controller = input$controller))
})
})
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With