用一个相同尺寸的Shiny-input替换两个Shiny-input

时间:2018-02-19 16:55:46

标签: r shiny

我在Shinyapp下面开发了:

ui <- fluidPage(
  fluidRow(                   
        column(width = 12, checkboxInput(inputId = "Chose", label = "Chose", value = TRUE, width = 170)),


        column(width = 12, fluidRow(splitLayout(cellWidths =  c(200, 200, 600), 
                    textInput(inputId = "Text1", label = "Text1", value = "30,000", width = 190),
                    sliderInput(inputId = "Slider1", label = "Slider1", min = 1, max = 30, value = 10, step = 0.10, post = "%", width = 310)))
        )
))
server <- function(input, output) {

}
shinyApp(ui, server)

现在,我想以这样的方式设计我的用户界面,当用户取消选中checkboxInput,然后textInputsliderInput将一起消失,另一个sliderInput(在我原来的textInputsliderInput的合并位置会弹出一些其他ID。

我已经探索了uiOutput可以做同样的事情,但我发现更新真的是1:1,而我的计划是2:1。

如果可以实现,有人可以共享指针。

感谢您的时间。

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

ui <- fluidPage(
  fluidRow(     
    column(width = 12, checkboxInput(inputId = "Chose", label = "Chose", value = TRUE, width = 170)),
    column(width = 12, fluidRow(splitLayout(cellWidths =  c(200, 200, 600), 
                                            uiOutput("test1"),
                                            uiOutput("test2"))),
           column(width = 12, fluidRow(splitLayout(cellWidths =  c(400, 600), 
                                                   uiOutput("test3")))

  ))
  ))
server <- function(input, output) {


  output$test1 <- renderUI({
    if(input$Chose == TRUE){
      sliderInput(inputId = "Slider1", label = "Slider1", min = 1, max = 30, value = 10, step = 0.10, post = "%", width = 310)
    }
  })

  output$test2 <- renderUI({
    if(input$Chose == TRUE){
      textInput(inputId = "Text1", label = "Text1", value = "30,000", width = 190)
    }
  })


  output$test3 <- renderUI({
    if(input$Chose == FALSE){
      sliderInput(inputId = "Slider2", label = "Slider2", min = 100, max = 300, value = 100, step = 0.10, post = "%", width = 600)
    }
  })

}
shinyApp(ui, server)