2016-11-28 8 views
1

메시지 또는 알림 항목이있는 머리글에 드롭 다운을 포함하면 클릭시 "You have 1 messages"라는 문구가 자동으로 표시됩니다. 어떻게하면 메시지 만 표시 할 수 있습니까? "당신은 1 개의 메시지가 있습니다."반짝이 대시 보드 헤더 드롭 다운 수정

아래의 예는 재현 :

ui <- dashboardPage(
    dashboardHeader(dropdownMenu(type = "messages", 
           messageItem(
           from = "Sales Dept", 
           message = "Sales are steady this month." 
           ))), 
    dashboardSidebar(), 
    dashboardBody() 
) 

server <- function(input, output) { } 

shinyApp(ui, server) 

답변

4

그 문장이 dropdownMenu 기능에 하드 코딩되어 나타납니다

function (..., type = c("messages", "notifications", "tasks"), 
      badgeStatus = "primary", icon = NULL, .list = NULL) 
{ 
    type <- match.arg(type) 
    if (!is.null(badgeStatus)) validateStatus(badgeStatus) 
    items <- c(list(...), .list) 
    lapply(items, tagAssert, type = "li") 
    dropdownClass <- paste0("dropdown ", type, "-menu") 
    if (is.null(icon)) { 
     icon <- switch(type, messages = shiny::icon("envelope"), 
     notifications = shiny::icon("warning"), tasks = shiny::icon("tasks")) 
    } 
    numItems <- length(items) 
    if (is.null(badgeStatus)) { 
     badge <- NULL 
    } 
    else { 
     badge <- span(class = paste0("label label-", badgeStatus), 
         numItems) 
    } 
    tags$li(
     class = dropdownClass, 
     a(
      href = "#", 
      class = "dropdown-toggle", 
      `data-toggle` = "dropdown", 
      icon, 
      badge 
     ), 
     tags$ul(
      class = "dropdown-menu", 
      tags$li(
       class = "header", 
       paste("You have", numItems, type) 
      ), 
      tags$li(
       tags$ul(class = "menu", items) 
      ) 
     ) 
    ) 
} 

우리는 문장이 paste("You have", numItems, type)에 내장되어 있음을 참조하십시오.

ui <- dashboardPage(
    dashboardHeader(dropdownMenuCustom(type = "messages", 
            customSentence = customSentence, 
           messageItem(
           from = "Sales Dept", 
           message = "Sales are steady this month." 
           ))), 
    dashboardSidebar(), 
    dashboardBody() 
) 

server <- function(input, output) { } 

shinyApp(ui, server) 
+0

그래서 함께 문장 전체 덮어 쓰기를 제거 :

customSentence <- function(numItems, type) { paste("This is a custom message") } # Function to call in place of dropdownMenu dropdownMenuCustom <- function (..., type = c("messages", "notifications", "tasks"), badgeStatus = "primary", icon = NULL, .list = NULL, customSentence = customSentence) { type <- match.arg(type) if (!is.null(badgeStatus)) shinydashboard:::validateStatus(badgeStatus) items <- c(list(...), .list) lapply(items, shinydashboard:::tagAssert, type = "li") dropdownClass <- paste0("dropdown ", type, "-menu") if (is.null(icon)) { icon <- switch(type, messages = shiny::icon("envelope"), notifications = shiny::icon("warning"), tasks = shiny::icon("tasks")) } numItems <- length(items) if (is.null(badgeStatus)) { badge <- NULL } else { badge <- span(class = paste0("label label-", badgeStatus), numItems) } tags$li( class = dropdownClass, a( href = "#", class = "dropdown-toggle", 'data-toggle' = "dropdown", icon, badge ), tags$ul( class = "dropdown-menu", tags$li( class = "header", customSentence(numItems, type) ), tags$li( tags$ul(class = "menu", items) ) ) ) } 

하는 A 최소한의 예 : 그 변경 한 가지 방법은 당신이 원하는 문장으로 새 매개 변수를 사용 새로운 기능을 작성하는 것입니다 빈 공간 - 또는 짧은 커팅이있을 것인가? – user7066213

+0

이것은 오류를 제공합니다 : 오류 : 'tagAssert'객체가 없습니다 - 아이디어가 있습니까? – user7066213

+0

게시하기 전에 코드를 시도하지 않았습니다. 죄송합니다. – denrou