gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:01:37 31 4
gpt4 key购买 nike

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

这是我希望能奏效但没有奏效的:
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 或索引,我可以使用它来确定单击了哪个通知。这可能吗?

最佳答案

这个答案完全基于@Batanichek 的这个概念:https://stackoverflow.com/a/34413701/3463439如问题评论中所引用。
ui.R:

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

服务器.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,并确保我使用此信息进行我需要的任何更新。

关于r - 在 shinydashboard 中获取最近点击的下拉菜单的 notificationItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34418993/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com