r shiny error Error in as.vector(x, “character”) : cannot coerce type 'closure' to vector of type 'character'

二次信任 提交于 2019-12-02 10:15:53

Main problem in your code is that you give reactive function "a1" as argument to sqlQuery function. sqlQuery expects you to give character as argument.

In this case where you want to monitor any changes in input. You could use observe function. I also added error checking line to make sure that you actually have some value in a input$idnumb

shinyServer(function(input, output) {
         library(RODBC)
         library(sqldf)
            observe({
            if(input$idnumb ==NULL)
               return(NULL)
            acc_con1 = odbcConnect("AdvWrk", uid="... ", pwd="... ")
            sql1 = sqlQuery(acc_con1, paste0('select Title from dbo.Employee where EmployeeID=',input$idnumb))
            )}
        output$emptitle = renderTable(print(sql1))
 )}

I also agree with @Mikael Jumppanen that

Main problem in your code is that you give reactive function "a1" as argument to sqlQuery function. sqlQuery expects you to give character as argument.

However the solution is much simpler: you should simply call a1() instead of a1 since you have defined it as a reactive function.

 sql1 = sqlQuery(acc_con1, paste0('select Title from dbo.Employee where EmployeeID=',a1()))

Can you please try it?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!