我有一个包含多个表的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"))
我该怎么做。
暂无答案!
目前还没有任何答案,快来回答吧!