在Shiny App中未找到MySQL表(“未找到对象”错误,但MySQL中存在表)

在Shiny App中未找到MySQL表(“未找到对象”错误,但MySQL中存在表),mysql,r,shiny,rmysql,Mysql,R,Shiny,Rmysql,我有一个闪亮的应用程序,它应该收集表单中的数据,并将其附加到MySQL中的数据表test中。我正在使用RMySQL移植到数据库中。应用程序还应该显示数据帧。我使用“save”和“load”函数来完成此操作,我认为连接是有效的,但由于某些原因,在部署应用程序时找不到表“object” 以下是错误: %s中的sprintfSELECT*出错,测试:找不到对象“测试” 当我删除load和/或save函数时,错误就会消失 这是我的global.R文件的一部分。查询是在用户输入定义要获取的数据类型后运行的

我有一个闪亮的应用程序,它应该收集表单中的数据,并将其附加到MySQL中的数据表test中。我正在使用RMySQL移植到数据库中。应用程序还应该显示数据帧。我使用“save”和“load”函数来完成此操作,我认为连接是有效的,但由于某些原因,在部署应用程序时找不到表“object”

以下是错误: %s中的sprintfSELECT*出错,测试:找不到对象“测试”

当我删除load和/或save函数时,错误就会消失

这是我的global.R文件的一部分。查询是在用户输入定义要获取的数据类型后运行的函数。在这个应用程序中,数据类型是MySQL数据库中的数据

# decide which function to use to save based on storage type
get_save_fxn <- function(type) {
  fxn <- sprintf("save_data_%s", type)

  fxn
}
save_data <- function(data, type) {
  fxn <- get_save_fxn(type)
  do.call(fxn, list(data))
}

# decide which function to use to load based on storage type
get_load_fxn <- function(type) {
  fxn <- sprintf("load_data_%s", type)

  fxn
}
load_data <- function(type) {
  fxn <- get_load_fxn(type)
  data <- do.call(fxn, list())

  # Just for a nicer UI, if there is no data, construct an empty
  # dataframe so that the colnames will still be shown
  if (nrow(data) == 0) {
    data <-
      matrix(nrow = 0, ncol = length(fields_all),
             dimnames = list(list(), fields_all)) %>%
      data.frame
  }
  data %>% dplyr::arrange(desc(timestamp))
}

load_data_mysql <- function() {
  on.exit(dbDisconnect(db))
  db <- dbConnect(RMySQL::MySQL(),user="name",
                  password="pass",
                  host="host",
                  dbname="bk")
  query <- sprintf("SELECT * FROM %s", test)
  data <- dbGetQuery(db, query)

}


save_data_mysql <- function(data) {
  on.exit(dbDisconnect(db))
  db <- dbConnect(RMySQL::MySQL(),user="name",
                  password="pass",
                  host="host",
                  dbname="bk")
  query <-
    sprintf("INSERT INTO %s (%s) VALUES ('%s')",
            test,
            paste(names(data), collapse = ", "),
            paste(data, collapse = "', '")
    )
  dbGetQuery(db, query)
}
这是我的服务器

 # Enable the Submit button when all mandatory fields are filled out
 observe({
   fields_filled <-
     fields_mandatory %>%
     sapply(function(x) !is.null(input[[x]]) && input[[x]] != "") %>%
     all

   shinyjs::toggleState("submit", fields_filled)
 })

 # Gather all the form inputs
 form_data <- reactive({
   sapply(fields_all, function(x) x = input[[x]])
 })

 # When the Submit button is clicked 
 observeEvent(input$submit, {
   # Update the timestamp field to be the current time
   updateTextInput(session, "timestamp", value = get_time_epoch())

   # User-experience stuff
   shinyjs::disable("submit")
   shinyjs::show("submitMsg")
   shinyjs::hide("error")
   on.exit({
     shinyjs::enable("submit")
     shinyjs::hide("submitMsg")
   })

   # Save the data (show an error message in case of error)
   tryCatch({
     save_data(form_data(), input$storage)
     shinyjs::reset("form")
     updateTabsetPanel(session, "mainTabs", "viewTab")
   },
   error = function(err) {
     shinyjs::text("errorMsg", err$message)
     shinyjs::show(id = "error", anim = TRUE, animType = "fade")      
     shinyjs::logjs(err)
   })
 })

 # Update the responses whenever a new submission is made or the
 # storage type is changed
 responses_data <- reactive({
   input$submit
   load_data(input$storage)
 })

 # Show the responses in a table
 output$responsesTable <- DT::renderDataTable(
   DT::datatable(
     responses_data(),
     rownames = FALSE,
     options = list(searching = FALSE, lengthChange = FALSE, scrollX = TRUE)
   )
 )

 # Allow user to download responses
 output$downloadBtn <- downloadHandler(
   filename = function() { 
     paste0(TEST_INPUT, "_", input$storage, "_", get_time_human(), '.csv')
   },
   content = function(file) {
     write.csv(responses_data(), file, row.names = FALSE)
   }
 )

您没有定义名为testanywhere的变量…@hadley-test是MySQL数据库中的表。我应该在某个地方为test指定一个test值吗?那么您的查询应该类似于:query@PorkChop-结果是无法找到签名“MySQLConnection,noquote”的函数“dbGetQuery”的继承方法