在shinydashboard的dashboardHeader函数中,可以添加多个菜单,比如通知的下拉菜单。当显示通知时,用户点击特定的通知是很自然的,以获取更多信息或采取一些行动。我希望能够检测到用户点击了哪个通知项,并根据它做一些事情(例如更新地图、显示包含与该通知相关的数据的表格等)。
这是我希望的工作,但没有:
ui.R
dashboardPage(
dashboardHeader(dropdownMenuOutput("dropdownmenu")),
dashboardSidebar(),
dashboardBody(textOutput("notificationoutput"))
)
服务器.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 或索引。那可能吗?