2016-08-15 11 views
0

私はユーザーにファイル(.csv)を入力させたいと思います。そのファイルから、2つのselectizeInputsに.csvの列名が入力されます。アップロードされたファイルのどの列がy変数であり、どの列がx変数であるかをユーザーに尋ねます。これで、私はできました。複数のselectizeInput from fileInput

私はできないことは次のとおりです。x変数のドロップダウンメニューのx変数の選択肢から消えるようにy変数の選択を取得したいと思います。

また、私はanswer to this questionを使用して助けようとしましたが、fileInputの値を使用していません。このように、下にある私のコードを動作させることはできません。ご指摘いただきありがとうございます。

ui<- fluidPage(

    titlePanel("Test"), 

    sidebarPanel(
    fileInput(inputId = "file1", label = "Upload File"), 
    selectizeInput(
     "sampleyvars", "Y-vars", choices = NULL, multiple = FALSE 
    ), 
    selectizeInput(
     "samplevars", "X-vars", choices = NULL, multiple = TRUE 
    ) 

), 

    mainPanel(h3("Nothing special") 
) 
) 

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

    observe({ 
    file1 <- input$file1 
    if(is.null(file1)){return()} 
    dataSet <- read.csv(file=file1$datapath) 

    vals1<-input$sampleyvars 
    vals2<-input$samplevars 

    updateSelectizeInput(session, "sampleyvars", 
         choices = colnames(dataSet)[! vals1 %in% vals2]) 
    updateSelectizeInput(session, "samplexvars", 
         choices =colnames(dataSet)[! vals2 %in% vals1]) 
    }) 

} 

shinyApp(ui = ui,server = server) 

答えて

0

あなたはX変数のウィジェットの間違ったIDを持っていた:samplevars代わりにsamplexvarsあなたはupdate*機能で使用します。私はそれを後者のIDに変更し、希望の効果を得るためにあなたのコードを少し微調整しました。


全例:

ui<- fluidPage(

    titlePanel("Test"), 

    sidebarPanel(
    fileInput(inputId = "file1", label = "Upload File"), 
    selectizeInput(
     "sampleyvars", "Y-vars", choices = NULL, multiple = FALSE 
    ), 
    # you had ID here wrong 
    selectizeInput(
     "samplexvars", "X-vars", choices = NULL, multiple = TRUE 
    ) 

), 

    mainPanel(h3("Nothing special") 
) 
) 

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

    data <- reactive({ 
    file1 <- input$file1 
    req(file1) 
    dataSet <- read.csv(file=file1$datapath) 
    vars <- colnames(dataSet) 

    updateSelectizeInput(session, "sampleyvars", "Y-vars", 
         choices = vars, selected = vars[1]) 
    updateSelectizeInput(session, "samplexvars", choices = vars[-1], selected = vars[2]) 

    dataSet 
    }) 

    observe({ 
    varX <- colnames(data()) 
    varX <- varX[!(varX %in% input$sampleyvars)] 
    updateSelectizeInput(session, "samplexvars", "X-vars", choices = varX) 
    }) 

} 

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

ああ...そんなにありがとう!それがまさに私が必要としていたものです。 – abet

関連する問題