【发布时间】:2015-04-29 17:32:04
【问题描述】:
在尝试将用户输入的输入 (empId) 从 Shiny UI 传递到 Shiny 服务器上的 sql 查询中时。r 不确定如何调试此错误。
Error in as.vector(x, "character") :
cannot coerce type 'closure' to vector of type 'character'
UI.r
library(shiny)
shinyUI(fluidPage(
titlePanel("Employee Table (AdventureWorks)"),
sidebarLayout(
sidebarPanel((""),
textInput("idnumb", "Employee ID number",""),
submitButton("Ok")),
mainPanel(tableOutput("emptitle")))))
服务器.r
shinyServer(function(input, output) {
library(RODBC)
library(sqldf)
a1 = reactive({ (input$idnumb) })
acc_con1 = odbcConnect("AdvWrk", uid="... ", pwd="... ")
sql1 = sqlQuery(acc_con1, paste0('select Title from dbo.Employee where EmployeeID=',a1))
output$emptitle = renderTable(print(sql1))
})
为了测试我的查询是否有效,我用下面的 sql 中的实际 EmployeeID 对此感到厌烦
.
.
sql1 = sqlQuery(acc_con1, paste0('select Title from dbo.Employee where EmployeeID = 8'))
.
.
我得到一个正常的输出,
Title
Production Technician - WC10
当我尝试使此响应用户输入时,我看到 as.vector(x, "character") 中的错误:无法将类型“闭包”强制转换为类型为“字符...错误...需要帮助”。
【问题讨论】:
标签: sql r parameter-passing shiny shiny-server