Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate input parameters #1656

Closed
bborgesr opened this issue Apr 5, 2017 · 5 comments
Closed

Validate input parameters #1656

bborgesr opened this issue Apr 5, 2017 · 5 comments

Comments

@bborgesr
Copy link
Contributor

bborgesr commented Apr 5, 2017

We should do input validation and print a message/warning when things are off. For example, for numericInput(), we allow the min being greater than the max or the value out of the min-max range, without any indication something is off...

@bklingen
Copy link

bklingen commented Apr 5, 2017

An idea would be to have the input flash in red, like I believe it did in earlier versions of shiny and not accept the input, i.e., revert to the previous state.

Previous references for numericInput: #1593 (about accepting characters), #927, #1022

@stla
Copy link

stla commented May 20, 2017

I personally use a simple css:

input:out-of-range {
  background-color: #FFCCCC;
}

The css input:invalid also acts when the "step" is not respected, and this is not what I want in general.

@chanioman
Copy link

chanioman commented Aug 28, 2017

@stla could you elaborate a bit more how you do this?

Maybe a MWE?
thanks in advance


Figured it out myself. Sorry stla.

(adding it for noobs like me):

library(shiny)

ui <- fluidPage(
tags$style(HTML("
input:invalid {
background-color: #FFCCCC;
}")),

numericInput("myValue", "My Variable", min = 0, max = 1, step = 0.5, value = 0.5),
numericInput("myValue2", "My Variable2", min = 0, max = 3, step = 0.5, value = 0.5),
textOutput("text"),
textOutput("text2")
)

server <- function(input, output) {
output$text <- renderText(input$myValue)
output$text2 <- renderText(input$myValue2)
}

shinyApp(ui, server)

@MadhulikaTanuboddi
Copy link

Another potential improvement with numeric input validation. With max value set, it is possible to give a number beyond that if we clear the numeric text and type the number. For example, one of the shiny-examples, 050-kmeans-example, max is set to 9 for cluster count. However, I am able to provide any number past 9 and the cluster responds. So, as @bklingen mentioned, probably resetting to the previous value when something is off is a good idea.
050-kmeans-cluster_count

@cpsievert
Copy link
Collaborator

Closing since we now have https://github.com/rstudio/shinyvalidate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants