Ferroao
Ferroao

Reputation: 3044

reactive object in dropdownmenu in shinydashboard

Is it possible to render the dashboard header dropdownmenu or a notificationitem based on a reactive object? My try didn't work.

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)

Upvotes: 0

Views: 1107

Answers (1)

mlegge
mlegge

Reputation: 6913

Yes, this is explained in the documentation for shinydashboard with a renderMenu and dropdownMenuOutput:

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)

Upvotes: 2

Related Questions