sv_integer {shinyvalidate} | R Documentation |
Validate that a field is a number that is integer-like
Description
The sv_integer()
function validates that a field is 'integer-like' with the
{value} %% 1 == 0
test. Very large values (generally with absolute exponent
values greater than 15) won't be validated correctly due to floating point
imprecision. By default, only a single, finite, not-missing, valid numbers
are allowed, but each of those criteria can be controlled via arguments.
Usage
sv_integer(
message = "An integer is required",
allow_multiple = FALSE,
allow_na = FALSE,
allow_nan = FALSE
)
Arguments
message |
The validation error message to use if a value is not an integer. |
allow_multiple |
If |
allow_na , allow_nan |
If |
Value
A function suitable for use as an
InputValidator$add_rule()
rule.
See Also
The sv_numeric()
function, which tests whether a field value is
simply numeric.
Other rule functions:
compose_rules()
,
sv_between()
,
sv_email()
,
sv_equal()
,
sv_gte()
,
sv_gt()
,
sv_in_set()
,
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("count", "Count")
)
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_integer()` works well with its
# defaults; a message will be displayed if the
# validation of `input$count` fails
iv$add_rule("count", sv_integer())
# Finally, `enable()` the validation rules
iv$enable()
}
shinyApp(ui, server)
}