2015-05-11 44 views
0

假設我有光澤的應用程序是這樣的:無功輸入?

## 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) 

我如何能顯示sigma_y只有當輸出==連續和mean_y只有當輸出==二進制?

我嘗試添加if(input$Output=="Continuous")但是,這並不工作:(

謝謝!

回答

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)