Shinydashboard notification item with link in new tab


I want to create a shinydasbhoard with notifications items, that link to another webpage.

#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>     box

header <- dashboardHeader(
  title = "Dashboard Demo",
  # Dropdown menu for notifications
  dropdownMenu(type = "notifications", badgeStatus = "warning",
               notificationItem(icon = icon("users"), status = "info", 
                                text = "", href = ""

  ui = dashboardPage(
  server = function(input, output) { }

I want the link to open in a new tab.
I've tried with the follwing text argument:
text = htmltools::a(href = "", target="_blank", "")
But this somehow breaks the layout:


How can I accomplish this without breaking the layout?

Hi, @duringju211,

This is breaking the layout because of the way shinydashboard::notificationItem() works. Let's take a look:

function (text, icon = shiny::icon("warning"), status = "success", 
    href = NULL) 
    tagAssert(icon, type = "i")
    if (is.null(href)) 
        href <- "#"
    icon <- tagAppendAttributes(icon, class = paste0("text-", 
    tags$li(a(href = href, icon, text))

As you can see, shinydashboard::notificationItem() is returning a li element with an a element already created; by passing in a second a element as the text parameter, you end up creating two a elements within the li element. This is the resulting HTML:

  <a href="#">
    <i class="fa fa-users text-info"></i>
  <a href="" target="_blank"></a>

Unfortunately, as you can see from the implementation of shinydashboard::notificationItem(), there is no way to specify the target attribute of the a element. This leaves you with two options:

  1. Creating a custom notificationItem() implementation that accepts more arguments in order to keep (more or less) the same functionality, like so:
notificationItemWithAttr <- function(text, icon = shiny::icon("warning"), status = "success", href = NULL, ...) {
  if (is.null(href)) 
    href <- "#"
  icon <- tagAppendAttributes(icon, class = paste0("text-", 
  tags$li(a(href = href, icon, text, ...))

Note: the tagAssert and validateStatus functions are not exported form shinydashboard and have been omitted from this custom implementation. While you can access them using :::, it is recommended that you either ask the package maintainer to export the function you need, or write your own version of it.

This can then be used to specify the target (as well as other attribtues) like so:

notificationItemWithAttr(icon = icon("users"), status = "info", text = "", href = "", target = "_blank")
  1. Replace the shinydashboard::notificationItem() call with the tags$li() call directly:
  a(href = "",
    target = "_blank",
    tagAppendAttributes(icon("users"), class = "text-info"),

Hope this helps!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.