title: R Shiny: invoking Shiny.onInputChange via session$sendCustomMessage
body: <p>I'm building a Shiny app that has a table where the user can select and highlight cells. When the user hits the go button, the app is supposed to send the positions of the user-selected cells to the server. </p>
  
  <p>I'm hitting the wall with the client to server communication. Below is the minimum reproducible example--why doesn't it work?</p>
  
  <pre><code>library(shiny)
  
  script &lt;- '
      Shiny.addCustomMessageHandler("jsCode", function(message) { 
          eval(message.value);
      });
      function hello() {
          console.log("hello from function hello!");
      };
  '
  
  ui &lt;- fluidPage(
      tags$head(tags$script(HTML(script))),
      actionButton("go", label = "Run")
  )
  
  
  server &lt;- function(input, output, session) {
  
      observeEvent(input$go, {
  
          session$sendCustomMessage(type='jsCode', 'Shiny.onInputChange("foo", "bar");')
  
          print(input$foo) # output is NULL
  
          session$sendCustomMessage(type='jsCode', 'hello();')
          # this does not work either. This is how I originally intended to do this. 
          # By defining a javascript function that aggregates the user selection data and 
          # send it to the server via Shiny.onInputChange
  
      })
  
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>I've seen alternate solutions where an onclick event is bound to the button and then it assigns a random value to some input variable but it seems convoluted to me and I'm not sure why this wouldn't work but that would. </p>
  
  <p>I'm using R version 3.4.3 and shiny_1.0.5. Thanks.</p>