I've built a Shiny app that has a popup message if a user puts in a non-numeric value into a numericInput. The code below does just that (using shinyBS
), but it reacts too quickly. If the user starts entering text, but needs to think a little about the number to put in, the message pops up. I'd like the observeEvent to trigger when the input loses focus, so the user has time to enter the full value, and only when they move on to the next input does the observeEvent handle the error. Any suggestions? I'm not wedded to using shinyBS
if there's a better solution out there, I built this app like 4 years ago and the Shiny universe has grown considerably since then.
library(shinyBS)
library(shiny)
ui<-shinyUI(fluidPage(
fluidRow(
numericInput("value","My Value",value=0),
bsModal("number_Message", "", trigger="", size = "small","This field only accepts numeric values.")
)
))
server<-shinyServer(function(input, output, session){
output$value<-renderText({input$value})
observeEvent(input$value,{
# browser()
if(is.na(as.numeric((input$value)))==T){
toggleModal(session, "number_Message",toggle="toggle")
updateNumericInput(session,"value","My Value",value=0)
}
})
})
shinyApp(ui = ui, server = server)