There is quite a lot of code in this section doing quite a lot of different things, so we'll step through each chunk in turn:
<script type="text/javascript"> // Shiny function to receive messages Shiny.addCustomMessageHandler("sendMessage", function(message) { // call this before modifying the DOM Shiny.unbindAll();
The first part carries out two functions; Shiny.addCustomMessageHandler("sendMessage", function(message){...}) registers the message-handler with Shiny. The "sendMessage" name was defined in the server.R function in the session$sendCustomMessage(type = 'sendMessage', message = theNumber) call. This is the first step in receiving and processing messages from the server.
The second part begins the process of reading ...