我想将MySQL与Shiny(R)连接起来。我一直在尝试运行代码,因为它不起作用。以下是我的代码:
library(shiny)
library(leaflet)
library(DBI)
library(RMySQL)
saveData <- function(firstname, lastname) {
db <- dbConnect(MySQL(), dbname = "example", host = "localhost",
port = 3306, user = "root",
password = "xxxx")
query <- sprintf(
"INSERT INTO %s (%s) VALUES ('%s, %s')",
name,
paste(names(firstname), collapse = ", "),
paste(data, collapse = "', '"),
paste(names(lastname), collapse = ", "),
paste(data, collapse = "', '")
)
dbGetQuery(db, query)
dbDisconnect(db)
}
ui <- fluidPage(
textInput("Firstname", "Enter your first name:", ""),
textInput("Surname", "Enter your last name:", ""),
actionButton("UpdateView", icon("refresh"))
)
server <- function(input, output, session) {
isolate(observeEvent(input$UpdateView, saveData(input$Firstname,
input$Surname)))
}
shinyApp(ui, server)
.local(drv,...)出错: 无法连接到数据库:错误:在“读取授权数据包”时失去与MySQL服务器的连接,系统错误:10060
Stack trace (innermost first):
72: .local
71: dbConnect
70: dbConnect
69: saveData [#3]
68: observeEventHandler [#8]
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
ERROR: [on_request_read] connection reset by peer
以下错误是一致的。我试图谷歌它,我发现防火墙可能是导致这个问题的那个,但没有提供关于防火墙中要更改的设置的步骤。如果解决方案是别的,那么我愿意做出这些改变。提前致谢