Description Usage Arguments Note See Also Examples
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, colourInput, passwordInput, textAreaInput. Note that
actionButton
is not supported, meaning that you cannot reset
the value of a button back to 0.
1 | reset(id)
|
id |
The id of the input element to reset or the id of an HTML tag to reset all input elements inside it. |
shinyjs
must be initialized with a call to useShinyjs()
in the app's ui.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | if (interactive()) {
library(shiny)
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) {
observeEvent(input$resetName, {
reset("name")
})
observeEvent(input$resetGender, {
reset("gender")
})
observeEvent(input$resetLetter, {
reset("letter")
})
observeEvent(input$resetAll, {
reset("form")
})
}
)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.