如何使用mysql数据库在shiny dashboard中动态生成下拉菜单?

6gpjuf90  于 2021-06-24  发布在  Mysql
关注(0)|答案(0)|浏览(250)

我有一个包含多个表的mysql数据库。现在我想在shiny dashboard中创建一个下拉菜单,根据表中每列的唯一值自动添加值。
我连接数据库的代码是

library(RMySQL)

options(mysql = list(
 "host" = "localhost",
 "port" = 3306,
 "user" = "root",
 "password" = "root"
))

databaseName <- "Apilogs"
table <- "Eventlog"

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 eventlog", table)
    # Submit the fetch query and disconnect
    data <- dbGetQuery(db, query)
    dbDisconnect(db)
    data
}

现在我在侧边栏中有了我的下拉列表

selectInput("region", "Region:",
              choices = colnames("I WANT TO POPULATE THIS FROM THE DB"))

我该怎么做。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题