Skip to content

Numeric input validation fails #87

@dmuenz

Description

@dmuenz

This example code using the sv_numeric rule function, which I copied from the package help pages (https://rstudio.github.io/shinyvalidate/reference/sv_numeric.html), fails for me:

library(shiny)
library(shinyvalidate)

ui <- fluidPage(
  textInput("rating", "Rating")
)

server <- function(input, output, session) {
  iv <- InputValidator$new()
  iv$add_rule("rating", sv_numeric())
  iv$enable()
}

shinyApp(ui, server)

When I run the app and enter a valid number, e.g. the number 1, the validator does not remove the "A number is required" error message.

I checked a few other numeric rule functions and they all had problems too. If I reuse the above code but swap in sv_integer(), then within the app an error message is immediately displayed saying "An unexpected error occurred during input validation: non-numeric argument to binary operator". This is before I've even tried to type anything. Additionally, a warning is displayed in the console:

Warning: Error in %%: non-numeric argument to binary operator
  74: withCallingHandlers
  73: suppressWarnings
  72: rule_fn
  71: <Anonymous>
  69: rule$rule
  55: <Anonymous>
  54: mapply
  53: self$`_validate_impl`
  52: self$validate
  51: ::
shiny
observe
  50: <observer>
   3: runApp
   2: print.shiny.appobj
   1: <Anonymous>

If I again reuse the above code but swap in sv_between(0, 100), then the validator accepts some numbers but not others in the range. E.g., I found that 0, 1, 10, and 100 are all considered valid, but 5 is considered invalid.

I also checked some non-numeric rule functions, specifically sv_email and sv_in_set, and both seemed to work fine in my limited testing. So the package isn't totally broken on my computer, and the issue seems to be limited to the numeric rule functions.

Here's my session info:

Details

R version 4.5.1 (2025-06-13 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default
LAPACK version 3.12.1

locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] shinyvalidate_0.1.3 shiny_1.11.1

loaded via a namespace (and not attached):
[1] digest_0.6.37 later_1.4.2 R6_2.6.1 httpuv_1.6.16
[5] fastmap_1.2.0 magrittr_2.0.3 glue_1.8.0 cachem_1.1.0
[9] memoise_2.0.1 htmltools_0.5.8.1 lifecycle_1.0.4 promises_1.3.3
[13] cli_3.6.3 xtable_1.8-4 sass_0.4.10 jquerylib_0.1.4
[17] compiler_4.5.1 rstudioapi_0.17.1 tools_4.5.1 bslib_0.9.0
[21] mime_0.13 Rcpp_1.1.0 jsonlite_2.0.0 rlang_1.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions