我有一个基本的RShiny应用程序,它有一个被动复选框,根据复选框中 Select 的数据(DF列)绘制时间序列数据.我当前的代码生成了一个带有如下复选框输入的UI:
# Load R packages
library(shiny)
library(shinyBS)
##example df in similar format to the data I'm working with
Both <- data.frame(
Year = c("1990", "1991", "1992", "1993"),
SST_anomaly_GOM = c("-1.1", "0.23", "0.87", "-0.09"),
SST_anomaly_GB = c("-1.1", "0.23", "0.87", "-0.09"),
SST_anomaly_MAB = c("-1.1", "0.23", "0.87", "-0.09"),
BT_anomaly_GOM = c("-2.5", "0.55", "1.20", "-0.19"),
BT_anomaly_GB = c("-1.1", "0.05", "1.24", "-0.29"),
BT_anomaly_MAB = c("-1.1", "-1.08", "0.67", "-2.40")
)
# Define UI
ui <- fluidPage(
# useShinyBS
"Visualizing Indicators", #app title
tabPanel("", # tab title
sidebarPanel(width=6,
checkboxGroupInput("variable", label = "Checkbox", choiceNames = gsub("_", " ", colnames(Both[2:7])),
choiceValues = colnames(Both[2:7]),
),
), # sidebarPanel
), #tabPanel
) # fluidPage
#Define Server:
server<- function (input,output){
output$rendered <- renderUI({
})
}
# Create Shiny object
shinyApp(ui = ui, server = server)
这将生成如下所示的界面:
这很好,但有一点重复,随着我最终想要将更多的时间序列变量包括到这个列表中,这对用户来说可能会变得很麻烦,并且会占用UI上的大量空间来以这种方式列出所有内容.
我的问题是,我如何调整我的代码,使其生成一个界面,其中列出唯一的变量,然后 for each 感兴趣的子区域勾选框?(GOM、BG、MAB等) 我脑海中的一个例子是一个界面,它看起来更像这样:
这个是可能的吗?是否可以使用我当前具有的格式的df(例如我的示例df称为"Both").
谢谢!