title: Shiny apps: How to use variable from server to create a new Input Widget
body: <p>I successfully got a variable from Shiny server back to the client with the function <em>session$sendCustomMessage</em> in server.R</p>
  
  <p>Now I want to use this <em>leftChoices</em> variable in the ui.R client to create a widget chooserInput to create a [custom input control][1] but this is not working [1]: <a href="http://shiny.rstudio.com/gallery/custom-input-control.html" rel="nofollow">http://shiny.rstudio.com/gallery/custom-input-control.html</a></p>
  
  <p>I've tried to use Shiny.chooserInput but in vain. the script doesn't recognize chooserInput and I don't know how to make it work. Some help. Thanks</p>
  
  <p>Here is ui.R</p>
  
  <pre><code>source("chooser.R")
  library(shiny)
  shinyUI(fluidPage(sidebarLayout(sidebarPanel(
                              fileInput("file1", "Choose file to upload",
                                        accept = c('text/csv','.csv')
                                       )
                                ),
                    mainPanel(
                              tabPanel("Data",shiny::dataTableOutput("contents")),
                              tags$script(src = "initcsv.js"),
                              chooserInput("mychoice", "Available", "Selected ",
                      colnames(message.leftChoices) , c(), size = 10, multiple = TRUE
                                                   )
                              )
                   )
    )
  )
  </code></pre>
  
  <p>Here is ny server.R</p>
  
  <pre><code>library(shiny)
  source("chooser.R")
  shinyServer(function(input, output, session) {
    data &lt;- reactive ({
      inFile &lt;- input$file1
      if (is.null(inFile))
        return(NULL)
      read.csv(inFile$datapath)
  
    })
    observe({
      session$sendCustomMessage(type = "MyDatasetUpdated", 
                                message = list(
                                  leftChoices=colnames(data())
                                              )
                                )
    })
    output$contents &lt;- renderDataTable(
      data(), options = list(iDisplayLength = 5)
    )
  })
  </code></pre>
  
  <p>Here is INITCSV.JS</p>
  
  <pre><code>Shiny.addCustomMessageHandler("MyDatasetUpdated",
                                function(message) {
                                  if  (message.leftChoices != null)
                                  //chooserInput("mychoice", "Available", "Selected ",
                                  //c() , c(), size = 10, multiple = TRUE
                                  //       ),
                                    alert(JSON.stringify(message.leftChoices));
                                  })
  </code></pre>