sv_in_set {shinyvalidate} | R Documentation |
Validate that a field is part of a defined set
Description
The sv_in_set()
function checks whether the field value is a member of a
specified set of values.
Usage
sv_in_set(
set,
message_fmt = "Must be in the set of {values_text}.",
set_limit = 3
)
Arguments
set |
A vector or list of elements for which the field value must be a
part of ( |
message_fmt |
The validation error message to use if a value fails to
match the rule. The message can be customized by using the
|
set_limit |
The limit of |
Value
A function suitable for use as an
InputValidator$add_rule()
rule.
See Also
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()
Examples
## 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)
}