首页 > 解决方案 > 当 selectInput() 改变时从 sliderInput() 更改为 numericInput()

问题描述

这很笼统,但是使用这种方法(见下文)在原始代码中使用它时会引发多个关于 if 语句的警告(这里太长了,无法展示)。那么,是否有任何适当的方法可以从何时切换sliderInput()到更改?非常感谢...numericInput()selectInput()

编辑:示例未正确复制。代码现在返回警告。错误显然value = c(0, 10)在于 in numericInput(),这当然需要一个值。原谅我跳进去...

library(shiny)

ui <- fluidPage(
  selectInput("option", "Select option", c("Slider", "Numeric")),
  uiOutput("op")
)

server <- function(input, output, session){
  output$op <- renderUI(
    if(input$option == "Slider"){
      sliderInput(inputId = "sip", 
                  label = "Slider", 
                  min = 0, 
                  max = 10, 
                  value = c(0, 10))
    } else {
      if(input$option == "Numeric"){
        numericInput(inputId = "nip", 
                     label = "Numeric", 
                     min = 0, 
                     max = 10,
                     value = c(0, 10)) #Single value required
      }
    }
  )
}

shinyApp(ui = ui, server = server)

标签: rshiny

解决方案


推荐阅读