2017-11-11 11 views
0

안녕하세요 저는 데이터를 입력하고 작업하는 Shiny App을 보유하고 있습니다. 하지만 이제 하위 집합에 대한 요인을 선택하는 액션 버튼이 필요합니다. 문제는 앱을 시작하고 데이터를 입력 할 때 요소가 없다는 것입니다. 작업 버튼을 처음 클릭하면 요소에 데이터의 열 이름이 표시됩니다.R shiny : 입력 후 모든 인수

어떻게 데이터를 읽은 후 요인이 나에게 직접 표시되도록 프로그래밍 할 수 있습니까? 도와 줘서 고마워! 여기

는 UI 및 서버의 일부

   radioButtons(
        "fileType_Input", 
        label = h5("Choose file type and click on browse"), 
        choices = list(".csv" = 1, ".xlsx" = 2), 
        selected = 1, 
        inline = TRUE 
       ), 

       fileInput('file1', '' ), 

       selectInput("letters", label=NULL, factors, multiple = TRUE), 

       actionButton("choose", "Auswahl"), 

       verbatimTextOutput("list") 

는 서버 :

shinyServer(function(input, output, session) { 

    # Get the upload file 
    myData <- reactive({ 
    inFile <- input$file1 

    if (is.null(inFile)) { 
     return(NULL) } 

    if (input$fileType_Input == "1") { 
     read.csv2(inFile$datapath, 
       header = TRUE, 
       stringsAsFactors = FALSE) 
    } else { 
     read_excel(inFile$datapath) 
    } 
    }) 

    # When the Choose button is clicked, add the current letters to v$choices 
    # and update the selector 
    observeEvent(input$choose, { 
    data <- myData() 
    factors <- colnames(data) # get the names of the Factors in a Vector to select them 
    v$choices <- input$letters # append(v$choices,input$letters) 
    updateSelectInput(session, "letters", 
         choices = factors #[!factors %in% v$choices)] 
    ) 
    }) 

    output$list <- renderPrint({ 
    v$choices 
    }) 

답변

0

대신 input$choose에 대한 observeEvent에 코드를 넣어 당신은에서 관찰 넣을 수 있습니다. 다음과 같이 입력하십시오 :

observe({ 

    if(!is.null(myData())) 
    { 
     data <- myData() 
     factors <- colnames(data) # get the names of the Factors in a Vector to select them 
     v$choices <- input$letters # append(v$choices,input$letters) 
     updateSelectInput(session, "letters", 
         choices = factors #[!factors %in% v$choices)] 
    ) 
    } 
    }) 

희망 하시겠습니까?

+0

도움을 주셔서 감사합니다. 불행히도 상상했던대로 작동하지 않습니다. 나는 "observevent"를 유지하고 "factor"벡터가 설정되면 데이터로드 후에 함수를 설치하고 싶습니다. 그래서 그는 저에게 직접 표시 될 수 있습니다. 만약 당신이 그것을 제안하는 방식으로, 내 버튼은 더 이상 작동하지 않습니다. – Zorro

+0

그러면 observe에 넣는 대신 반응식 안에 updateSelectInput을 넣을 수 있습니다. – SBista

+0

Sry하지만 나는 당신의 생각을 이해하지 못합니다. 나는 반응적인 표현을 시도했지만, 나는 아직도 그 길을 가고 있습니다. 다시 나에게 설명해 주시겠습니까? – Zorro