我有一个基本的 RShiny 应用程序,它有一个反应式复选框,它根据复选框中选择的数据(df 列)绘制时间序列数据。我当前的代码生成一个带有复选框输入的用户界面,如下所示:
# 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 上的大量空间来列出所有内容这样。
我的问题是如何调整我的代码,使其生成一个界面,其中列出了唯一变量,然后为每个感兴趣的子区域勾选了复选框? (GOM、BG、MAB 等) 我想到的一个例子是一个看起来更像这样的界面:
这可能吗?使用我目前拥有的格式的 df 是否可能(例如我的示例 df 称为“两者”)。
谢谢!