How do I make it so that Shiny waits a little bit for the user to input their zip code (without using a button). The problem I'm facing is that it will quickly jump to the error if the user isn't fast enough at inputting their zip code. Edit:
- I have other user inputs in this app, but I simplified it in this question. I want all of the other inputs to be reacted to right away since they are radioButtons. I think pressing 'return' would still do the same thing as a button, which isn't what I'm looking for. I was thinking about using ' Sys.sleep()' only for the zipcode input and not for the others. Would that be possible?
library(shiny)
shinyApp(ui <- fluidPage(sidebarPanel(
"",
textInput("zipcode", label = "Enter your zipcode.", value = 98125)
)) ,
server <- function(input, output, session) {
observeEvent(input$zipcode, {
#limits zipcode input to 5 numbers only
if (nchar(input$zipcode) != 5)
{
updateTextInput(session, 'zipcode', value = 98125)
showModal(
modalDialog(
title = "Error!",
"Only 5-character entries are permitted.",
easyClose = TRUE
)
)
}
if (is.na(as.numeric(input$zipcode)))
{
showModal(
modalDialog(
title = "Error!",
"Only numeric values are allowed. Please try again.",
easyClose = TRUE
)
)
}
})
})