rstudio/shiny — pull request #148 by wch (2013-04-18 18:45:07+00:00)
Title: Add support for sending arbitrary messages to client

This pull request replaces #146. It does two things:

* Adds support for sending arbitrary JSON messages to the client.
* Adds support for registering Javascript callbacks on the client, to handle the JSON messages.

This will make it easier for app/package authors to add their own communication channels from the server to the client.

Example app at: https://github.com/wch/testapp/tree/master/message-handler-inline

```
devtools::install_github('shiny', 'wch', 'sendmessage')
library(shiny)
runGitHub('testapp', 'wch', subdir='message-handler-inline')
```

Another example, with a separate JS file to load the message handler, instead of inline Javascript:

https://github.com/wch/testapp/tree/master/message-handler-jsfile

```
runGitHub('testapp', 'wch', subdir='message-handler-jsfile')
```

Notes:

* When app authors send messages, they are wrapped into an object named `custom`.
* The order in which callbacks are called is the same as the order that they were added.
* The order of `values` and `errors` is slightly different; the code for them was previously interleaved, but now it's not. I don't know if the old way was intentional or not.