Learn R Programming

shiny.destroy (version 0.1.0)

removeInput: Remove Input from Shiny Session

Description

The removal of the named input in a shiny session.

Usage

removeInput(
  id,
  selector = paste0("#", id),
  session = getDefaultReactiveDomain()
)

Value

An invisible `TRUE` value confirming that the input has been removed.

Arguments

id

Input value name

selector

The HTML selector to remove the UI for. By default it is the tag where the ID matches the input, but might need to be adjusted for different inputs.

session

The Shiny session to remove the input from

Details

If the input is a standard shiny input e.g. `numericInput`, then to remove the label as well as the input, set the selector to be `paste0(":has(> #", id, ")")`

Examples

Run this code
if (FALSE) { # interactive()
library(shiny)
library(shiny.destroy)

ui <- fluidPage(
  numericInput("number", "Select number:", 5, 1, 10),
  p("Selected number:", textOutput("number_out", inline = TRUE)),
  actionButton("delete", "Remove input")
)

server <- function(input, output, session) {
  output$number_out <- renderText(input$number %||% "input unavailable")

  observeEvent(
    input$delete,
    removeInput("number", selector = ":has(> #number)")
   )
}

shinyApp(ui, server)
}

Run the code above in your browser using DataLab