title: “first argument“ error when using shinyapps.io, rodbc to show sql query result in web
body: <p>First of all, I need to use R to get SQL query result from HANA database, which I finish by using RODBC in Rstudio.</p>
  
  <p>Second of all, I need to share my code with others, which I use shinyapps.io to finish.</p>
  
  <p>However, I need to use shinyapps to show my SQL query result on other computers, which I have the following error message:</p>
  
  <pre><code>error first argument is not an open rodbc channel
  </code></pre>
  
  <p>I used the answer from <a href="https://stackoverflow.com/questions/23275144/r-shiny-rodbc-connection-failing">R shiny RODBC connection Failing</a>, but it still does not work.</p>
  
  <p>Here is my codes for ui.R and sever.R attached:</p>
  
  <p>ui.R:</p>
  
  <pre><code>library(dplyr)
  library(RODBC)
  library(stringr)
  library(ggplot2)
  fluidPage(
    titlePanel("Basic DataTable"),
    fluidRow(
      DT::dataTableOutput("table")
    )
  )
  </code></pre>
  
  <p>sever.R:</p>
  
  <pre><code>library(dplyr)
  library(RODBC)
  library(stringr)
  library(ggplot2)
  ch&lt;-odbcConnect('HANARB1P',uid='****',pwd='****')
  options(scipen = 200)
  myOffice &lt;- 0
  StartDate &lt;- 20170601
  EndDate &lt;- 20170610
  office_clause = ""
  if (myOffice != 0) {
    office_clause = paste(
      'AND "_outer"."/BIC/ZSALE_OFF" IN (',paste(myOffice, collapse=", "),')'
    )
  }
  function(input, output) {
    output$table &lt;- DT::renderDataTable(DT::datatable({
    data &lt;- sqlQuery(channel=ch,query=paste(' SELECT TOP 100
                                                     "/BIC/ZSALE_OFF" AS "SalesOffice",
                                                     "/BIC/ZHASHPAN" AS "CreditCard"
                                              FROM "SAPB1P"."/BIC/AZ_RT_A212"
                                              WHERE "CALDAY" BETWEEN',StartDate,'AND',EndDate,'
                                                    ',office_clause,'
                                 '))
      data
    }))
  }
  </code></pre>
  
  <p>How to use shinyapps.io and RODBC to show the SQL query result on the webpages for sharing?</p>
  
  <p>According to the answer, I revised my code a little bit. But something weird happens again. When I use the code:</p>
  
  <pre><code>function(input, output) {
    output$table &lt;- DT::renderDataTable(DT::datatable({
      data &lt;- sqlQuery(channel=ch,query=paste(' SELECT TOP 50
                                                   "/BIC/ZSALE_OFF" AS "SalesOffice",
                                                       "/BIC/ZHASHPAN" AS "CreditCard"
                                                FROM "SAPB1P"."/BIC/AZ_RT_A212"
                                                WHERE "CALDAY" BETWEEN',StartDate,'AND',EndDate,'
                                                      ',office_clause,'
                                              '))
      data
    }))
  }
  </code></pre>
  
  <p>I have the error information:</p>
  
  <p><a href="https://i.stack.imgur.com/amAxy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/amAxy.png" alt="enter image description here"></a></p>
  
  <p>When I use the code:</p>
  
  <pre><code>shinyServer(
  function(input, output) {
    data &lt;- sqlQuery(channel=ch,query=paste(' SELECT TOP 50
                                                   "/BIC/ZSALE_OFF" AS "SalesOffice",
                                                       "/BIC/ZHASHPAN" AS "CreditCard"
                                                FROM "SAPB1P"."/BIC/AZ_RT_A212"
                                                WHERE "CALDAY" BETWEEN',StartDate,'AND',EndDate,'
                                                      ',office_clause,'
                                              '))
    output$table &lt;- DT::renderDataTable(data)
  }
  )
  </code></pre>
  
  <p>I have the error information:</p>
  
  <p><a href="https://i.stack.imgur.com/EIjy2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EIjy2.png" alt="enter image description here"></a></p>
  
  <p>I am sure the channel works. If I just use run app to do this:</p>
  
  <pre><code>shiny::runApp('//paper/fchen4/feng.officeworks/mycode/myShiny')
  </code></pre>
  
  <p>It works fine. But I work in a company, I do not know if my firewall could have something to do with this error. But if I do not use SQL here, it is OK.</p>