我正在尝试将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
中使用它。有任何建议吗?
答案 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))
}