## Only run examples in interactive R sessions
if (interactive()) {
library(shiny)
library(shinyvalidate)
ui <- fluidPage(
textInput("number", "Number")
)
server <- function(input, output, session) {
# Validation rules are set in the server, start by
# making a new instance of an `InputValidator()`
iv <- InputValidator$new()
# Basic usage: `sv_equal()` requires a value
# to compare against the field value; a message
# will be shown if the validation of
# `input$number` fails
iv$add_rule("number", sv_equal(1))
# Finally, `enable()` the validation rules
iv$enable()
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab