Reputation: 865
I am developing the Shiny app in which if the user enters non-numeric characters, the value should be changed to the value mentioned in updateNumericInput().
Here is my Rcode
library(shiny)
ui <- fluidPage (
numericInput("current", "Current Week",value = 40, min = 40, max = 80)
)
server <- function(input, output, session) {
observeEvent(input$current, {
updateNumericInput(session,"current", value = ({ if(!(is.numeric(input$current))){40}
if(!(is.null(input$current) || is.na(input$current))){
if(input$current < 40){
40
}else if(input$current > 80){
80
} else{
return (isolate(input$current))
}
}
})
)
})
}
shinyApp(ui=ui, server = server)
Can anyone help me with this code?
Upvotes: 1
Views: 1491
Reputation: 29407
Something like this?
library(shiny)
ui <- fluidPage (
numericInput("current", "Current Week",value = 40, min = 40, max = 80)
)
server <- function(input, output, session) {
observeEvent(input$current, {
updateNumericInput(session,"current", value = ({ if(!(is.numeric(input$current))){40}
else if(!(is.null(input$current) || is.na(input$current))){
if(input$current < 40){
40
}else if(input$current > 80){
80
} else{
return (isolate(input$current))
}
}
else{40}
})
)
})
}
shinyApp(ui=ui, server = server)
Upvotes: 1