在 shinydashboard 中获取最近点击的下拉菜单的 notificationItem

Get the most recently clicked notificationItem of a dropdownmenu in shinydashboard

在shinydashboard的dashboardHeader函数中,可以添加多个菜单,比如通知的下拉菜单。当显示通知时,用户很自然地会点击特定的通知,以获取更多信息或采取一些行动。我希望能够检测到用户点击了哪个 notificationItem,并根据它做一些事情(例如更新地图,显示 table 以及与该通知相关的数据等)。

这是我希望能起作用但不起作用的方法:
ui.R

dashboardPage(  
  dashboardHeader(dropdownMenuOutput("dropdownmenu")),  
  dashboardSidebar(),  
  dashboardBody(textOutput("notificationoutput"))  
)  

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$notificationoutput = renderText({
    if(is.null(input$dropdownmenu)){
      notificationitemid = "a"
    }else{
      notificationitemid = input$dropdownmenu 
    }
    return(notificationitemid)
  })
})

在我的理想世界中,类似这样的操作会将 "a" 更新为一个 id 或索引,我可以使用它来确定单击了哪个通知。这可能吗?

这个答案完全基于@Batanichek 的这个概念: 如问题评论中所引用。
ui.R:

dashboardPage(
  dashboardHeader(dropdownMenuOutput("dropdownmenu")),
  dashboardSidebar(),
  dashboardBody(
    tags$script(HTML("function clickFunction(link){ 
                   Shiny.onInputChange('linkClicked',link);
                     }")),
    textOutput("notificationoutput")
    )
)

server.R

server = shinyServer(function(input, output, session){
  output$dropdownmenu = renderMenu({
    aa = notificationItem(text = "moo", href = "www")
    aa$children[[1]]=a(href="#","onclick"=paste0("clickFunction('","moo","'); return false;"),aa$children[[1]]$children)
    dropdownMenu(type = "notifications", badgeStatus = "warning",
                 aa,
                 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$notificationoutput = renderText({
    if(is.null(input$linkClicked)){
      notificationitemid = "a"
    }else{
      notificationitemid = input$linkClicked 
    }
    return(notificationitemid)
  })
})

我现在需要做的就是确保每个 notificationItem 都有一个我跟踪的不同 ID,并且我使用此信息进行我需要的任何更新。