Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShinyDashboard: badgeLabel in menuSubItem

I'm trying to include badgeLabel into the menuSubItem like this:

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")
            )
)

But I get the error:

Error in menuSubItem("Sub Item2", tabName = "subI2", badgeLabel = "beta", : unused arguments (badgeLabel = "beta", badgeColor = "blue")

If I put it in menuItem, it works just fine, but I need it in menuSubItem. Any sugestions?

like image 904
Vesnič Avatar asked Sep 05 '25 03:09

Vesnič


1 Answers

menuSubItem does not have this argument. Thus you would need to write your own menuSubItem function:

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))
}
like image 79
thothal Avatar answered Sep 07 '25 20:09

thothal