ShinyDashboard:menuSubItem中的badgeLabel

时间:2019-03-07 08:17:48

标签: r shiny shinydashboard

我正在尝试将badgeLabel包含在menuSubItem中,如下所示:

sidebarMenu(id="tabs",
            menuItem("First Item",tabName="Item1"),
            menuItem("Secon Item", tabName = "Item2", icon = icon("bell"),
                     menuSubItem("Sub Item1",tabName="subI1"),
                     menuSubItem("Sub Item2",tabName="subI2", badgeLabel = "beta", badgeColor = "blue")
            )
)

但是我得到了错误:

  

menuSubItem(“ Sub Item2”,tabName =“ subI2”,badgeLabel =   “ beta” ,:未使用的参数(badgeLabel =“ beta”,badgeColor =   “蓝色”)

如果我将其放在menuItem中,它可以正常工作,但我需要在menuSubItem中使用它。有任何建议吗?

1 个答案:

答案 0 :(得分:2)

menuSubItem没有此参数。因此,您将需要编写自己的menuSubItem函数:

menuSubItem2 <- function (text, tabName = NULL, href = NULL, newtab = TRUE, 
                          icon = shiny::icon("angle-double-right"), 
                          selected = NULL, badgeLabel = NULL, badgeColor = "green") {
    if (!is.null(href) && !is.null(tabName)) {
        stop("Can't specify both href and tabName")
    }
    isTabItem <- FALSE
    target <- NULL
    if (!is.null(badgeLabel)) {
        badgeTag <- tags$small(class = paste0("badge pull-right bg-", 
            badgeColor), badgeLabel)
    }
    else {
        badgeTag <- NULL
    }

    if (!is.null(tabName)) {
        shinydashboard:::validateTabName(tabName)
        isTabItem <- TRUE
        href <- paste0("#shiny-tab-", tabName)
    }
    else if (is.null(href)) {
        href <- "#"
    }
    else {
        if (newtab) 
            target <- "_blank"
    }
    tags$li(a(href = href, `data-toggle` = if (isTabItem) 
        "tab", `data-value` = if (!is.null(tabName)) 
        tabName, `data-start-selected` = if (isTRUE(selected)) 
        1
    else NULL, target = target, icon, span(text), badgeTag))
}