I am looking to add a custom news button to the header of my shinyapp, which will display information from a specific dataset. I want the button to show the number of news items available, similar to how
shinyDashboard::notificationItem()
works but with more customization. However, since I am new to JavaScript, I am unsure how to concatenate the strings 'News' and '5' to display 'News (5)' on the button.
In addition to displaying the news count, clicking the button should eventually render a new UI with the actual news content.
Any assistance on achieving this would be greatly appreciated!
library(shiny)
ui = navbarPage(title = "Dashboard",
tags$script(
HTML(
"Shiny.addCustomMessageHandler(
type = 'num', function(message) {
var newsCount = message
var header = $('.navbar > .container-fluid');
header.append('<div><input value = \"News (" + newsCount + \")\" type = \"button\" class = \"btn action-button\"></div>');
});"
)
)
)
server = function(input, output, session){
session$sendCustomMessage(type = "num", message = 5)
}
shinyApp(ui, server)