Learn R Programming

shinyjs (version 0.0.7.0)

reset: Reset input elements to their original values

Description

Reset any input element back to its original value. You can either reset one specific input at a time by providing the id of a shiny input, or reset all inputs within an HTML tag by providing the id of an HTML tag. Reset can be performed on any traditional Shiny input widget, which includes: textInput, numericInput, sliderInput, selectInput, selectizeInput, radioButtons, dateInput, dateRangeInput, checkboxInput, checkboxGroupInput. Buttons are not supported, meaning that you cannot use this function to reset the value of an action button back to 0.

Usage

reset(id)

Arguments

id
The id of the input element to reset or the id of an HTML tag to reset all input elements inside it.

Details

Note that this function only works on input widgets that are rendered in the UI. Any input that is created dynamically using uiOutput + renderUI will not be resettable.

See Also

useShinyjs, runExample

Examples

Run this code
if (interactive()) {
  runApp(shinyApp(
    ui = fluidPage(
      useShinyjs(),
      div(
        id = "form",
        textInput("name", "Name", "Dean"),
        radioButtons("gender", "Gender", c("Male", "Female")),
        selectInput("letter", "Favourite letter", LETTERS)
      ),
      actionButton("resetAll", "Reset all"),
      actionButton("resetName", "Reset name"),
      actionButton("resetGender", "Reset Gender"),
      actionButton("resetLetter", "Reset letter")
    ),
    server = function(input, output, session) {
      observeEvent(input$resetName, {
        reset("name")
      })
      observeEvent(input$resetGender, {
        reset("gender")
      })
      observeEvent(input$resetLetter, {
        reset("letter")
      })
      observeEvent(input$resetAll, {
        reset("form")
      })
    }
  ))
}

Run the code above in your browser using DataLab