shinyWidgets icon indicating copy to clipboard operation
shinyWidgets copied to clipboard

Calling `show_toast` before previous toast disappears causes "Duplicate IDs found" error to appear

Open Silentstrike46 opened this issue 7 months ago • 0 comments

Calling shinyWidgets::show_toast while an existing toast is being displayed while devmode is active causes errors to appear due to duplicate Input/Output IDs being found.

Repex triggering error (Reduced from example code in documentation for show_toast):

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  actionButton(
    inputId = "info",
    label = "Show info toast",
    icon = icon("info")
  )
)

server <- function(input, output, session) {
  observeEvent(input$info, {
    show_toast(
      title = "Heads up",
      text = "Just a message",
      type = "info",
      position = "top-end",
      timer = 10000
    )
  })
}

if (interactive()) {
  shiny::devmode(TRUE)
  shinyApp(ui, server)
}

Error message:

Duplicate input/output IDs found
The following IDs were repeated:
- "swal2-select": x inputs
- "swal2-checkbox": x inputs
- "swal2-textarea": x inputs

where x increases each time it is called.

Example video of reprex above triggering error: https://github.com/user-attachments/assets/e7dd0249-5d7e-4a3e-961c-a11a202eb6f4

As it stands I can't find a good way to close an existing toast via code, nor a good way to avoid this error (other than not spawning a second toast while another toast exists, which is inconvenient).

Silentstrike46 avatar Jul 26 '24 13:07 Silentstrike46