我正在开发Shiny应用程序,如果用户输入非数字字符,则应将值更改为updateNumericInput()中提到的值。
这是我的 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)
任何人都可以帮我这个代码吗?
答案 0 :(得分:0)
这样的东西?
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)