In many instances, you will want to send data from the R server to the JS client. Here is a very simple example:
library(shiny)
runApp(
list(
ui = fluidPage(
tags$script(
"Shiny.addCustomMessageHandler('message', function(params) { alert(params); });"
),
...