I am trying to create a dynamic notification on header on a shinyapp, and get an error message as Warning: Error in FUN: Expected an object with class 'shiny.tag'.
The code is as below,
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "test",
dropdownMenuOutput("menu")
),
dashboardSidebar()
,
dashboardBody()
)
server <- function(input, output, session) {
output$menu <- renderMenu({
items <- if(Sys.Date()>as.Date("2022-06-30")){
"June is over"
}else(
"June"
)
dropdownMenu(
type = "notifications",
.list = items
)
})
}
shinyApp(ui, server)
Couldn't figure out how to fix it. Any help?
if else
in one line.list
argument, you need create your items in a list.notificationItem
or messageItem
. Read this: https://rstudio.github.io/shinydashboard/structure.htmlHere is an example on how to fix:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "test",
dropdownMenuOutput("menu")
),
dashboardSidebar()
,
dashboardBody()
)
server <- function(input, output, session) {
output$menu <- renderMenu({
items <- list(
notificationItem(if(Sys.Date()>as.Date("2022-06-30"))"June is over" else "June"),
notificationItem("123")
)
dropdownMenu(
type = "notifications",
.list = items
)
})
}
shinyApp(ui, server)