1

这是我的 ui.R 和 server.R。我不确定为什么dashboardBody 中的标题不显示。

server.R

shinyServer(function(input, output){
})

ui.R

dashboardPage(
  dashboardHeader(title = "Analysis"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Data Pull", tabName = "dataPull", icon = icon("database"),
        dateInput("startDateInput", "What is the starting date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"),
        dateInput("endDateInput", "What is the ending date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en")
      ),
      menuItem("View Data", tabName = "dataView", icon = icon("table"),
               selectInput("dataViewSelectionInput", label = "Selection of Interest?", choices = c(1,2,3), multiple = TRUE),
               checkboxInput("dataViewAll", label = "View all pulled", value = TRUE)
               )
    )
  ),
  dashboardBody(
    tabItems(
     tabItem(tabName = "dataPull",
            h1("Data Selected")
     ),
     tabItem(tabName = "dataView",
             h2("Viewing Data")
     )
   )
  )
)
4

1 回答 1

1

目前,仪表板似乎不允许切换到选项卡并使用下拉菜单,我在这里找到了解决方法:

将此函数添加到 UI 或全局变量的开头:

convertMenuItem <- function(mi,tabName) {
    mi$children[[1]]$attribs['data-toggle']="tab"
    mi$children[[1]]$attribs['data-value'] = tabName
    mi
}

然后你的 ui 文件变成:

用户界面

dashboardPage(
  dashboardHeader(title = "Analysis"),
  dashboardSidebar(
    sidebarMenu(
      convertMenuItem(menuItem("Data Pull", icon = icon("database"),
                               dateInput("startDateInput", "What is the starting date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"),
                               dateInput("endDateInput", "What is the ending date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"), 
                               tabName = "dataPull"),
                      tabName="dataPull"),
      convertMenuItem(menuItem("View Data", icon = icon("table"),
                               selectInput("dataViewSelectionInput", label = "Selection of Interest?", choices = c(1,2,3), multiple = TRUE),
                               checkboxInput("dataViewAll", label = "View all pulled", value = TRUE),
                               tabName = "dataView"),
                      tabName="dataView")
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "dataPull",
              h1("Data Selected")
      ),
      tabItem(tabName = "dataView",
              h2("Viewing Data")
      )
    )
  )
)

这是因为 menuitem 中有一些默认行为,如果 menuItem 有子项,它不会设置 data-toggle 或 data-value 标签,所以我手动设置它们。(编辑删除错字)

于 2015-09-30T21:30:46.060 回答