Incorporating dropdown menu in navbar page

Hi all,

I am trying to incorporate Dropdownmenu in navbar page based on conditions. I have built a following code to achieve that. But unfortunately, the the dropdown is not getting displayed.

Basically, I just gave a condition (4 >3) that is true, then display the dropdown.

library(shiny)
library(lubridate)
library(shinydashboard)
ui <- shinyUI(
  fluidPage(
    tags$head(
      tags$style(HTML("
                      .navbar-nav .messages-menu a {padding-top: 0px; padding-bottom:0px}
                      .navbar-nav {width: 90%}
                      .navbar-nav .messages-menu {float: right; padding-top: 25px;}
                  "))
    ),
    navbarPage("Navbar!",
               tabPanel("Plot",
                        sidebarLayout(
                          sidebarPanel(),
                          mainPanel()
                        )
               ),
               tabPanel(dropdownMenuOutput("messageMenu")
                 # dropdownMenu(type = "messages",
                 #              messageItem(
                 #                from = "Sales Dept",
                 #                message = "Sales are steady this month."
                 #              )
                 # )
               )
    )   
  )
)

server <- function(input, output, session) {}
output$messageMenu <- renderMenu({
  
  if(4 > 3){
    dropdownMenu(type = "notifications",notificationItem(text =  "Open",status = "warning"))
  } else {
    dropdownMenu()
  } 
})
shinyApp(ui = ui, server = server)

You could use renderUI. In the example below the message will appear if the textbox value input is bigger then 3.

library(shiny)
library(lubridate)
library(shinydashboard)
ui <- shinyUI(
  fluidPage(
    tags$head(
      tags$style(HTML(
        "
    .navbar-header { width: 10% }
    .navbar-nav { width: 90% }
    .navbar-nav>li:nth-child(2) { float: right; }"))),
    navbarPage("Navbar!",
               tabPanel("Plot",
                        sidebarLayout(
                          sidebarPanel(
                            textInput("value", "value", 3)
                          ),
                          mainPanel()
                        )
               ),
               tabPanel(
                 uiOutput("messagesUI")
               )
               
    )   
  )
)

server <- function(input, output, session) {
  
output$messagesUI <- renderUI({
  
  if(input$value > 3){
  
    dropdownMenu(type = "messages",
               messageItem(
                 from = "Sales Dept",
                 message = "Sales are steady this month.")
    )
  }  
})
}
shinyApp(ui = ui, server = server)

Depending on what you want to do implementing notifications might be easier: