我想构建一个可能包含3个menuItem的仪表板侧边栏,当选择menuItem时,checkBoxGroup将在下面展开,用户可以选择任意数量的选项。我该怎么做呢?
这是我目前拥有的代码的相关部分。
# ui.R
dashboardSidebar(
# I need a header to say Select a Dataset
# I want the menuItems to be selectable but
menuItem("Dataset 1", newTab = FALSE),
menuItem("Dataset 2", newTab = FALSE),
menuItem("Dataset 3", newTab = FALSE),
# not sure where to put uiOutput so that it appears below
# the selected menuItem
uiOutput("features")
)
# server.R
dataset <- reactive({
df <- read.csv()
return(df)
})
output$features <- renderUI({
checkboxGroupInput("features", "Select features to plot: ",
colnames(df))
})
答案 0 :(得分:0)
这是你需要做的。然而,问题是您必须单击menuItem for Features,单击其他位置以填充它。我正试图解决这个问题。您还必须像函数一样调用dataset(),而不是df。
# ui.R
header <- dashboardPage(
dashboardHeader(title ="Data Frame Features", titleWidth = 350)
)
sidebar <- dashboardSidebar(
sidebarMenu(
# I need a header to say Select a Dataset
# I want the menuItems to be selectable but
menuItem("Dataset 1", newTab = FALSE),
menuItem("Dataset 2", newTab = FALSE),
menuItem("Dataset 3", newTab = FALSE),
menuItem("Dataframe Features",tabName = "features", icon = icon("th"), uiOutput("features"), selected = TRUE)
)
)
body <- dashboardBody(
tabItems(tabItem(tabName = "something")
)
dashboardPage(
header,
sidebar,
body
)
# server.R
dataset <- reactive({
df <- read.csv()
return(df)
})
output$features <- renderUI({
checkboxGroupInput("features", "Select features to plot: ", choices= colnames(dataset()), selected = colnames(dataset()))
})