我是新手,我试图建立一个应用程序。我得到一个错误

时间:2015-02-12 10:32:48

标签: r shiny shiny-server

error
sqlQuery(con,"insert into samp values('",input$text1,"',",input$text2,")");
Error in sqlQuery(con, "insert into samp values('", input$text1, "',",  :
  object 'input' not found
ui.R
library(shiny)
shinyUI(fluidPage(mainPanel(textInput("text1"," ",value = " "),
 numericInput("text2"," ",value = " "), actionButton("b1", label = "select"),
 tableOutput("txt1"))))
server.R
shinyServer(function(input,output){output$txt1<-renderTable({input$b1
if(input$b1==0 )return()isolate({con<-odbcConnect("sample",uid="amma",pwd ="amma")sqlTables(con)sqlQuery(con,"insertintosampvalues('",input$text1,"',",input$text2,")");sqlQuery(con,"select * from samp"); })})})

如何通过从接口接收值来编写插入查询?

1 个答案:

答案 0 :(得分:0)

好的,我已将您的代码添加到a gist,因此它更具可读性并可通过闪亮运行。

可以通过以下方式运行:

shiny::runGist("https://gist.github.com/corynissen/d52bdca7b7a8a1a8512a")

我在顶部添加了一个库(RODBC)调用,并在您尝试连接的字符串周围添加了paste0。看看是否有帮助......如果没有db,我无法真正测试它。