R Shiny removeUI is not working on selectInput

...

I have shiny selectInput with choices and a button. so when I click on the button shiny input has to be remove. But it is removing don't know why it is!. I have used shiny removeUI like below:

library(shiny)

  # Define UI
  ui <- fluidPage(
    actionButton("rmv", "Remove UI"),
    selectInput(
      inputId=paste("FilterOperator",1,sep = "_"),
      label = "",
      choices=sort(unique(c("Begins with","Equals to","Not Equals to","Contains","Not Contains"))),
      multiple=F,
      selectize = F

    )
  )

  # Server logic
  server <- function(input, output, session) {
    observeEvent(input$rmv, {
      removeUI(
        selector = paste("FilterOperator",1,sep="_"),
        multiple = TRUE,
        immediate = TRUE,
        session
      )
    })
  }

  # Complete app with UI and server components
  shinyApp(ui, server)

Is it removeUI wont work on selectInput? please help me anyone on this.

removeUI needs a string that is accepted by jQuery's selector

removeUI(
            selector = paste0("div:has(> #FilterOperator", "_", 1, ")"),
            multiple = TRUE,
            immediate = TRUE,
            session
        )
1 Like

Yes, it is removing UI but not completely. When I am trying to get the value after the removing the above UI, still it is returning with selected value before instead of NULL

This topic was automatically closed 21 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.