Shiny and JavaScript interaction with session$sendCustomMessage

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!!

Answers


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))
    })
  })
)

Need Your Help

cmake error while running on a mounted directory

windows linux cmake mount

I have issue running cmake on a package residing in a mounted folder. I have full permissions on this mounted folder.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.