## Only run examples in interactive R sessions
if (interactive()) {
library(shiny)
library(shinyvalidate)
ui <- fluidPage(
textInput("email", "Email")
)
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_optional()` is often paired with
# another `sv_*()` function; below, an email in
# `input$email` is not required, but if present, it
# must be valid
iv$add_rule("email", sv_optional())
iv$add_rule("email", sv_email())
# Finally, `enable()` the validation rules
iv$enable()
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab