The sv_in_set() function checks whether the field value is a member of a
specified set of values.
sv_in_set(
set,
message_fmt = "Must be in the set of {values_text}.",
set_limit = 3
)A vector or list of elements for which the field value must be a
part of (value %in% set must be TRUE) to pass validation. To allow an
empty field, NA should be included in the set vector. Optionally, NaN
can be included as well.
The validation error message to use if a value fails to
match the rule. The message can be customized by using the
"{values_text}" string parameter, which allows for the insertion of set
values (formatted internally as a text list and controlled via the
set_limit parameter). While the default message uses this string
parameter, it is not required in a user-defined message_fmt string.
The limit of set values to include in the
automatically-generated error message (i.e., when message = NULL, the
default). If the number of elements provided in set is greater than
set_limit then only the first <message_limit> set elements will be
echoed along with text that states how many extra elements are part of the
set.
A function suitable for use as an
InputValidator$add_rule() rule.
The sv_between() function, which tests whether a field values
between two boundary values.
Other rule functions:
compose_rules(),
sv_between(),
sv_email(),
sv_equal(),
sv_gte(),
sv_gt(),
sv_integer(),
sv_lte(),
sv_lt(),
sv_not_equal(),
sv_numeric(),
sv_optional(),
sv_regex(),
sv_required(),
sv_url()
## Only run examples in interactive R sessions
if (interactive()) {
library(shiny)
library(shinyvalidate)
ui <- fluidPage(
textInput("rating", "Rating")
)
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_in_set()` requires a value
# set given as a vector; a message will be
# shown if the validation of `input$rating` fails
iv$add_rule("rating", sv_in_set(1:5))
# Finally, `enable()` the validation rules
iv$enable()
}
shinyApp(ui, server)
}