我有一个包含多个表的MySQL数据库。现在,我想在Shiny仪表板中创建一个下拉菜单,该菜单会根据表格中每列的唯一值自动添加值。
我连接数据库的代码是
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"))
我该怎么办呢。