无功输入?

时间:2015-05-11 15:46:37

标签: r shiny

假设我的闪亮应用程序如下所示:

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(radioButtons("Output", "Continuous or binary:",
                                c("Continuous" = "Continuous",
                                  "Binary" = "Binary"), 
                                selected = "Continuous"), 
                   numericInput("sigma_y", "SD of y:", 0.1,
                                min = 0, max = NA, step = 0.01),
                   numericInput("mean_y", "mean_y:", 0.1,
                                min = 0, max = NA, step = 0.01)),
  dashboardBody()
)

server <- function(input, output) { }

shinyApp(ui, server)

如果output == continuous和mean_y仅在输出==二进制时才能显示sigma_y?

我尝试添加if(input$Output=="Continuous"),但这不起作用:(

谢谢!

1 个答案:

答案 0 :(得分:1)

动态创建numericInput

rm(list = ls())
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(radioButtons("Output", "Continuous or binary:",
                                c("Continuous" = "Continuous",
                                  "Binary" = "Binary"), 
                                selected = "Continuous"), 
                   uiOutput("test")),
  dashboardBody()
)

server <- function(input, output) { 

  output$test <- renderUI({ 
    if(input$Output=="Continuous")
    {
      numericInput("sigma_y", "SD of y:", 0.1,min = 0, max = NA, step = 0.01)
    }

    else if(input$Output=="Binary")
    {
      numericInput("mean_y", "mean_y:", 0.1,min = 0, max = NA, step = 0.01)
    }
    else
    {
      return()
    }
  })
}
shinyApp(ui, server)