How to save multiple rows in mySQL server from R SHINY app

How to save multiple rows of data in MySQL server from R Shiny? The following codes are only applicable for a single row:

saveData <- function(data ) {
  db <- dbConnect(MySQL(), dbname = "my_servername", host = options()$mysql$host, 
                  port = options()$mysql$port, user = options()$mysql$user, 
                  password = options()$mysql$password)
  query <- sprintf(
    "INSERT INTO %s (%s) VALUES ('%s')",
    "my_Table", 
    paste(names(data), collapse = ", "),
    paste(data, collapse = "', '")
  )
  dbGetQuery(db, query)
  dbDisconnect(db)
}

Looking for a help from expert. Thanks

Use the dbAppendTable() function

Thank you. I found the solution now. I used the following command:

 dbWriteTable(db, "my_table", data, overwrite = TRUE, row.names=F)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.