在加载时显示带有现有(动态创建的)menuSubItems的menuItem的内容(发光仪表板)

时间:2019-09-26 12:39:29

标签: r shiny shinydashboard

我有一个带有menuItem的应用程序,该应用程序还应在单击时显示一个选项卡,并附加几个menuSubItems。我在此处找到实现此目的的代码:Show content for menuItem when menuSubItems exist in Shiny Dashboard。加载应用后,应该显示菜单项上附加的标签"charts"。我之所以将附加到menuSubItems的选项卡存储在列表中,因为它们将在以后动态生成。

但是,当我打开应用程序时,"charts"的标签内容未显示。

library(shiny)
library(shinydashboard)

convertMenuItem <- function(mi,tabName) {
  mi$children[[1]]$attribs['data-toggle']="tab"
  mi$children[[1]]$attribs['data-value'] = tabName
  if(length(mi$attribs$class)>0 && mi$attribs$class=="treeview"){
    mi$attribs$class=NULL
  }
  mi
}

uiTabs <- function() {
  listTabs <- list(tabItem("charts","Charts Tab"),
                   tabItem("subitem1","Sub-item 1 tab content"),
                   tabItem("subitem2","Sub-item 2 tab content"),
                   tabItem("other","Other tab content"))
  do.call(tabItems, listTabs)
}

header <- dashboardHeader()

sidebar <- dashboardSidebar(
  sidebarMenu(
    convertMenuItem(menuItem("Charts", tabName = "charts",selected=T,
                             menuSubItem("Sub-item 1", tabName = "subitem1"),
                             menuSubItem("Sub-item 2", tabName = "subitem2")),"charts"),
    menuItem(tabName = "other", "Other tab")
  )
)

body <- dashboardBody(
  tabItems(
    uiOutput("tabs")
  )
)

shinyApp(
  ui = dashboardPage(header, sidebar, body),
  server = function(input, output) {
    output$tabs <- renderUI({uiTabs()})
  }
)

0 个答案:

没有答案