【发布时间】:2018-03-22 03:43:59
【问题描述】:
只是检查是否有解决此问题的方法: 我不希望用户在“输入编号 2”中输入高于允许最大值的值(无论在“输入编号 1”中输入什么)。 它在用户使用微调器时有效,但在用户仅输入值时无效。
library(shiny)
ui <- fluidPage(
numericInput(inputId = "inNumber1", label = "Input number 1",
value = 100, min = 10, max = 200, step = 10),
numericInput(inputId = "inNumber2", label = "Input number 2",
value = 50, min = 10, max = 200, step = 10),
textOutput("out1"),
textOutput("out2")
)
server <- function(input, output, session) {
# Reacting to changes in input 1:
observeEvent(input$inNumber1, {
number1 <- input$inNumber1 # value 1
updateNumericInput(session, inputId = "inNumber2",
label = "Input number 2",
value = floor(number1/2),
min = 10, max = number1, step = 10)
output$out1 <- renderText({number1})
})
# Reacting to changes in input 2:
observeEvent(input$inNumber2, {
number2 <- input$inNumber2 # value 2
output$out2 <- renderText({number2})
})
}
shinyApp(ui, server)
【问题讨论】:
-
最小值和最大值仅在您使用箭头更改输入时有效,但如果您键入它,它将不会像您的示例中那样起作用。您必须在服务器中使用 if 语句。
标签: r shiny numeric-input