如何将闪亮的输入滑块数据写入数据库(Mysql)?

时间:2018-10-20 19:45:52

标签: r shiny

嗨,我如何将用户(滑块等)的输入写入MySQL数据库。下面是我的代码,基本上我想要它,以便每当用户更改输入时,它都会在数据库中创建新行,然后另一个应用程序可以使用最新用户的输入在单独的应用程序中生成另一个计算。

将会有多个闪亮的应用程序,因为会有很多用户,我认为数据库会很好(有人推荐它),并且由于所有用户都有不同的会话,因此这应该是实现它的最佳方法。这是错误的思考方式吗?

library(shiny)
library(RMariaDB)
source("C:/Users/User/Desktop/xx")
source("C:/Users/User/Desktop/xx")
con <- dbConnect(RMariaDB::MariaDB(), user="placeholder", password="placeholder", 
dbname='xxxxx', host='localhost')
dbListTables(con, xxxxx)

ui <- 
fluidPage(
sidebarLayout(
  sidebarPanel(sliderInput("x1", "x1t", min = 0, max = 100, value = 
25), 
               sliderInput("y1", "y1t", min = 0, max = 100000, value = 15000),
               numericInput("z1", " z1t", min = 0, max = 100,
                            value = 68), selectInput("hi", "hit", 
                                                     list("Yes", "No"), selected = "Yes", multiple = FALSE,selectize = TRUE, width = NULL, size = NULL), 
               sliderInput("AMC", "AMCt:", min = 0, max = 100, value = 10, ),
               sliderInput("AGAG", "AGAGt", min = 0, max = 100, value = 10, post = "%"),
               sliderInput("EC5", "EC5t:", min = 0, max = 100, value = 12, post = "%"),
               sliderInput("EC6", "EC6t:", min = 0, max = 100, value = 11, post = "%")),
  mainPanel("main panel")
  )
)



server <- function(input, output){
slidervalues <- reactive(data.frame(x = c(input$x1), y = 
c(input$y1), 
         z = c(input$z1), a = 
c(input$hi), AMCd = c(input$AMC),AGAG5 = c(input$AGAG), 
         EEE = c(input$EC5), 
EER = c(input$EC6)))
observeEvent({dbWriteTable(con, "tbl_forecast", slidervalues(), append = 
TRUE)})
}
shinyApp(ui = ui, server = server)

0 个答案:

没有答案