2017-01-18 6 views
0

私は、サーバ機能でデータセットをロードしてから、ユーザに基づいて選ぶことができる光沢のあるアプリを作成しようとしています。 conditionalPanelを使用してチェックボックスをオンにします。 condtionalPanelの条件としてサーバーから変数を出力する方法はありますか?ここでShiny - conditionalPanel - サーバからの出力として条件を設定する

は、私が試したものです:

library(shiny) 
library(caret) 

ui <- fluidPage(
    selectInput('dataset', 'Select Dataset', 
       list(GermanCredit = "GermanCredit", 
        cars = "cars")), 

    conditionalPanel(
    condition = "output.factorflag == true", 
    checkboxInput("UseFactor", "Add Factor Variable") 
) 
) 


server <- function(input, output) { 
    # Loading the dataset 
    df <- reactive({ 
    if(input$dataset == "GermanCredit"){ 
     data("GermanCredit") 
     df <- GermanCredit 
    }else if(input$dataset == "cars"){ 
     data(cars) 
     df <- cars 
    } 

    return(df) 
    }) 

    # Loading the variables list 
    col_type <- reactive({ 
    col_type <- rep(NA,ncol(df())) 
    for(i in 1:ncol(df())){ 
     col_type[i] <- class(df()[,i]) 
    } 
    return(col_type) 
    }) 

    outputOptions(output, "factorflag", suspendWhenHidden = FALSE) 


    output$factorflag <- reactive({ 
    if("factor" %in% col_type()){ 
     factor.flag <- TRUE 
    } else {factor.flag <- FALSE} 
    } 
) 
} 


shinyApp(ui = ui, server = server) 

Thank you in advance! 

答えて

1

あなたは、ほとんどがあった、あなたはfactorflagの宣言の後outputOptionsを配置する必要があります。

library(shiny) 
library(caret) 

ui <- fluidPage(
    selectInput('dataset', 'Select Dataset', 
       list(GermanCredit = "GermanCredit", 
        cars = "cars")), 

    conditionalPanel(
    condition = "output.factorflag == true", 
    checkboxInput("UseFactor", "Add Factor Variable") 
) 
) 


server <- function(input, output) { 
    # Loading the dataset 
    df <- reactive({ 
    if(input$dataset == "GermanCredit"){ 
     data("GermanCredit") 
     GermanCredit 
    }else { 
     data("cars") 
     cars 
    } 
    }) 
    output$factorflag <- reactive("factor" %in% sapply(df(),class)) 
    outputOptions(output, "factorflag", suspendWhenHidden = FALSE) 
} 

shinyApp(ui = ui, server = server) 
+0

他の提案にも感謝しています。 –

関連する問題