Following this question and answer Get the most recently clicked notificationItem of a dropdownmenu in shinydashboard
I created the app below which nicely opens a sweetalert when clicking on a taskItem.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(tidyverse)
ui <- fluidPage(
dashboardPage(
dashboardHeader(dropdownMenuOutput("dropdownmenu")),
dashboardSidebar(),
dashboardBody(
tags$script(HTML("function clickFunction(link){ Shiny.onInputChange('linkClicked',link);}")),
)))
server = shinyServer(function(input, output, session){
output$dropdownmenu = renderMenu({
aa <- 1:2 %>%
map(~taskItem(text = paste("This is no", .), value = ., color = c("red", "blue")[.]))
for(i in 1:length(aa)){
aa[[i]]$children[[1]] <- a(href="#","onclick"=paste0("clickFunction('",paste("This is no", i),"'); return false;"),
aa[[i]]$children[[1]]$children)
}
dropdownMenu(type = "tasks", badgeStatus = "warning",
.list = aa)
})
observeEvent(input$linkClicked, {
sendSweetAlert(
session = session,
text = input$linkClicked,
type = "info",
showCloseButton = TRUE)
})
})
shinyApp(ui = ui, server = server)
But hitting the same taskItem twice will not open the sweetalert again. It will only be opened again when hitting another item in between. How to fix that?