title: Error in switch(code, ic9 = { : EXPR must be a length 1 vector
body: <p>Help me resolve this error:</p>
  
  <pre><code>Error in switch(code, ic9 = { : EXPR must be a length 1 vector
  </code></pre>
  
  <p>When I switch from one radio button to another, it should start displaying the result for the radio button selected and the result associated with it. Thats why I've used the switch case, but there is error in it.</p>
  
  <p>CODE:</p>
  
  <pre><code>library(shiny)
  library(RPostgreSQL)
  shinyServer(function(input, output){
      # Return the requested dataset
      inputCode &lt;- reactive({
                              input$code
                              code &lt;&lt;- {switch(input$code,
                                            i9= ic9,
                                            i10= ic10)}
                              input$icd
                                    })
      dbConn &lt;- function(inputCode,out){
        con &lt;- dbConnect(dbDriver("PostgreSQL"), user="postgres", password="xyz", dbname="ICD_9_10_Mapping", host = "localhost", port = 5432)
        on.exit(dbDisconnect(con), add=TRUE)
        query1 &lt;- "SELECT icd_10_codes, description, flags FROM icd_9_10_dia WHERE icd_9_codes ='"
        query2 &lt;- "SELECT icd_9_codes, description, flags FROM icd_10_9_dia WHERE icd_10_codes ='"
        switch(code,
               ic9 = {X &lt;&lt;- query1},
               ic10 = {X &lt;&lt;- query2})
        invert &lt;- "'"
          stmt &lt;- paste(X,toString(input$icd, width = 10),invert, sep = "")
          res &lt;- dbSendQuery(con, statement = stmt)
          out &lt;&lt;- fetch(res, n = -1)
      }
        output$out1 &lt;- renderTable(dbConn(inputCode,out))})
  </code></pre>