Strange bugs with insertUI function with dropdown in shinyWidgets

When I use the insertUI function to add a new dropdown button, there will be a strange bug that the added one won't be triggered in anyway.

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  dropdown(
    label = "old",
    inputId = "old",
    tagList(
      selectInput("s1","s1","1"),
      selectInput("s2","s2","1")
    )
  ),
  actionButton("epiDataPanelAddBtn","add"),
  actionButton("epiDataPanelDesBtn","des")
)

server <- function(input, output, session) {
  observeEvent(input$epiDataPanelAddBtn,{
    insertUI(
      selector = paste0("#epiDataPanelAddBtn"),
      where = "afterEnd",
      ui = dropdown(
        label = "new",
        inputId = "new",
        tagList(
          selectInput("s1","s1","1"),
          selectInput("s2","s2","1")
        )
      ),
      session = session
    )
  })
  
  observeEvent(input$epiDataPanelDesBtn,{

  })
}

shinyApp(ui, server)

You can find that the 'old' dropdown can be triggered by click, while 'new' dropdown won't.
That's very strange.
Is there any method to solve this ?
Thank you
Dy

There is a general principle that things in shiny that you want to keep track of need unique ID's to facilitate this and breaking these conventions can put your applications in hard to predict configurations with unpredictable results.
As such this small innovation of labelling the dropdown with a new unique id (also I modified the label to reveal what this is; but that part is just for show and not necessary)

      ui = dropdown(
        label   = paste0("new",input$epiDataPanelAddBtn),
        inputId = paste0("new",input$epiDataPanelAddBtn),

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.