闪亮的输入到mysql数据库

时间:2016-02-29 09:29:53

标签: mysql r shiny

我是R的新人,有光泽。我想使用R studio构建一个应用程序,在这种情况下会出现一些需要将用户输入存储在数据库中的情况。我很乐意使用Mysql。我的问题是用户数据输入没有存储在数据库中。

我哪里错了?

服务器

library(RMySQL)

options(mysql = list(
"host" = "localhost",

"user" = "root",
"password" = "mysql"
))
databaseName <- "myshinydatabase"
table <- "responses"

saveData <- function(data) {
# Connect to the database
db <- dbConnect(MySQL(), dbname = databaseName, host = options()$mysql$host, 
              port = options()$mysql$port, user = options()$mysql$user, 
              password = options()$mysql$password)
# Construct the update query by looping over the data fields
query <- sprintf("INSERT INTO %s (%s) VALUES ('%s')",        table,input$name,input$data) 
 # Submit the update query and disconnect
dbGetQuery(db, query)
dbDisconnect(db)
 }

 loadData <- function() {
 # Connect to the database
 db <- dbConnect(MySQL(), dbname = databaseName, host =    options()$mysql$host, 
              port = options()$mysql$port, user = options()$mysql$user, 
              password = options()$mysql$password)
 # Construct the fetching query
 query <- sprintf("SELECT * FROM %s", table)
 # Submit the fetch query and disconnect
 data <- dbGetQuery(db, query)
 dbDisconnect(db)
 data

 }

UI

 library(shiny)
 shinyUI(
 fluidPage(div(
            textInput("name","Name",""),
            numericInput("data","Data",""),

            actionButton("submit","Submit","")
 ))
 )

0 个答案:

没有答案