Skip to content

Feature Request: Get id's of selected menuItem and notificationItem #114

@metanoid

Description

@metanoid

I mostly want this for notificationItems, but in crafting a minimal example I noticed that I couldn't actually get this for menuItems either. The basic idea is that when a user clicks on a specific notificationItem, I want to get which notificationItem was clicked, and do something based on that (e.g. change a DataTable to show data relevant to that notification). I can't find any way of getting that information. Here's an example:
ui.R

dashboardPage(
  dashboardHeader(dropdownMenuOutput("dropdownmenu")),
  dashboardSidebar(sidebarMenuOutput("sidebarmenu")),
  dashboardBody(tabItems(tabItem(tabName = "mytab",
                        textOutput("notificationoutput"),
                        textOutput("sidebaroutput"))))
)

server.R

server = shinyServer(function(input, output, session){
  output$dropdownmenu = renderMenu({
    dropdownMenu(type = "notifications", badgeStatus = "warning",
                 notificationItem(icon = icon("users"), status = "info",
                                  "5 new members joined today"
                 ),
                 notificationItem(icon = icon("warning"), status = "danger",
                                  "Resource usage near limit."
                 ),
                 notificationItem(icon = icon("shopping-cart", lib = "glyphicon"),
                                  status = "success", "25 sales made"
                 ),
                 notificationItem(icon = icon("user", lib = "glyphicon"),
                                  status = "danger", "You changed your username"
                 )
    )
  })
  output$sidebarmenu = renderMenu({
    sidebarMenu(menuItem("5 new members joined today",icon = icon("users"), tabName = "mytab"),
                menuItem("Resource usage near limit.",icon = icon("warning"), tabName = "mytab"),
                menuItem("25 sales made",icon = icon("shopping-cart", lib = "glyphicon"), tabName = "mytab"),
                menuItem("You changed your username",icon = icon("user", lib = "glyphicon"), tabName = "mytab"), 
                id = "mysidebar"
    )
  })
  output$notificationoutput = renderText({
    if(is.null(input$dropdownmenu)){
      notificationitemid = "a"
    }else{
      notificationitemid = input$dropdownmenu 
    }
    return(notificationitemid)
  })
  output$sidebaroutput = renderText({
    if(is.null(input$mysidebar)){
      sidebaritemid = "b"
    }else{
      sidebaritemid = input$mysidebar 
    }
    return(sidebaritemid)
  })

})

What I would like is for the values "a" and "b" to be updated when the user clicks on a notificationItem or menuItem. According to the documentation for ?sidebarMenu, this should already be happening, so maybe that's a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions