有条件的不起作用

时间:2017-06-30 13:59:50

标签: r rstudio shiny shinydashboard

我正在学习R和闪亮,并且一直试图使用闪亮的包文档here中的一些代码。我一直试图找出为什么我添加的条件不响应我的条件。 我做错了什么,因为我没有收到错误?

ui <- fluidPage(
  uiOutput("ex")
)
server <- function(input, output) {
  output$ex <- renderUI({
    tagList(
      selectInput("n","Please Select  :",
                  choices = c("N","U","T")),
      conditionalPanel(condition = "n"=="N",
                       textInput("inmean"," Mean:",0.25),
                       textInput("invsd","Sd", 0.02)),
      conditionalPanel(condition = "n"== "U",
                       textInput("inmean","Mean:",0.25),
                       textInput("insd","Sd", 0.02))
    )
  })
}
shinyApp(ui, server)  

1 个答案:

答案 0 :(得分:1)

就我个人而言,我不会这样做。我会使用一个观察({})语句来查看&#34; n&#34;的输入。并使用updateTextInput()来更改值。

但这似乎适用于您正在使用的方法:

ui <- fluidPage(

  selectInput("n","Please Select  :",
              choices = c("N","U","T")),
  uiOutput('ex')
)
server <- function(input, output) {
  output$ex <- renderUI({

      if(input$n == 'N'){
        tagList(
        textInput("inmean"," Mean:",0.25),
        textInput("invsd","Sd", 0.02)
        )
      }else if(input$n == 'U'){
        tagList(
        textInput("inmean","Mean:",0.2),
        textInput("insd","Sd", 0.01)
        )
      }

  })

}
shinyApp(ui, server)