在 shinydashboard 的下拉菜单中反应 object

reactive object in dropdownmenu in shinydashboard

是否可以呈现仪表板 header 下拉菜单或基于反应式 object 的通知项?我的尝试没有成功。

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
  dashboardHeader(uiOutput("drop")),
  dashboardSidebar(),
  dashboardBody()
)

server <- function(input, output) { 
  values<-reactiveValues()
  values[["numvotes"]]<-1
  output$drop<-renderUI({
    dropdownMenu(type = "notifications", badgeStatus = "warning",
                 notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
                                  paste(values[["numvotes"]],"vote(s)")
                 )                 )
  })
  }

shinyApp(ui, server)

是的,这在 shinydashboard 的文档中用 renderMenudropdownMenuOutput 进行了解释:

https://rstudio.github.io/shinydashboard/structure.html#dynamic-content

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
  dashboardHeader(dropdownMenuOutput("notif")),
  dashboardSidebar(),
  dashboardBody()
)

server <- function(input, output) { 
  values<-reactiveValues()
  values[["numvotes"]] <- 1

   output$notif <- renderMenu({
     dropdownMenu(type = "notifications", badgeStatus = "warning",
                  notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
                                   paste(values[["numvotes"]], "vote(s)")
                  )                 )
   })
}

shinyApp(ui, server)