【问题标题】:How to create a checkBoxGroup under a menuItem in shiny dashboard sidebar?如何在闪亮的仪表板侧边栏中的 menuItem 下创建一个 checkBoxGroup?
【发布时间】:2015-11-18 11:42:33
【问题描述】:

I'd like to build a dashboard sidebar that has maybe 3 menuItems and when a menuItem is selected a checkBoxGroup will expand below and the user can select any number of options.我该怎么办?

这是我目前拥有的代码的相关部分。

# 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))
})

【问题讨论】:

  • 您将需要探索 renderUI 和 outputUI,这将取决于其他输入。尝试使用一些代码,然后我们可以帮助您更好地理解它。

标签: r shiny rstudio shinydashboard


【解决方案1】:

这是你需要做的。但是,问题是您必须单击 menuItem 的功能,单击其他地方以填充它。我现在正在尝试解决这个问题。您还必须像函数一样调用 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()))
})

【讨论】:

    猜你喜欢
    • 2021-09-22
    • 2016-11-11
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 2016-12-05
    相关资源
    最近更新 更多