2017-12-10 1 views
1

다중 탭 응용 프로그램을 사용하려고합니다. 두 번째 탭의 페이지 레이아웃을 첫 번째 패널의 입력에 조건부로 사용하고 싶습니다. 기본적으로 첫 번째 패널의 값이 1 인 경우 사용자가 첫 번째 패널에 값 2를 입력 한 다음 두 번째 패널에 두 개의 파일 입력을 표시하려면 두 번째 패널에 파일 입력 세트를 표시하고 싶습니다. 현재 내 코드는 두 조건을 모두 표시하며 이유는 확실하지 않습니다. 아래에서 재현 가능한 코드를 참조하십시오.R shiny conditionalPanel 두 조건 모두 표시

ui = 
navbarPage("Page Title", 
    tabPanel("Panel 1", 
    sidebarPanel(
     ## Add Name, 
     ## Number of surveys analysising 
     numericInput("n_values", "Number of columns in next panel:", 1, min = 1, max = 2) 
    ), 
    mainPanel(
     tags$div(
     h2("Home Page") 
    ) 
    ) 
    ), 
    tabPanel("Panel 2", 
     conditionalPanel(condition = "input.n_values == 1", 
     fixedPage(theme = "flatly", 
      fixedRow(
      column(2,"First Column", 
       fileInput("File1", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F), 
       p("Click the button to check the data was read in correctly") 
      ), 
      fixedRow(
       column(12, 
       verbatimTextOutput("errorText") 
      ) 
      )  
     ) 
     ) 
    ), 
     conditionalPanel(condition = "input.n_values == 2", 
     fixedPage(theme = "flatly", 
      fixedRow(
      column(2,"First Column", 
       fileInput("File1", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F), 
       p("Click the button to check the data was read in correctly") 
      ), 
      column(2,"Second Column", 
       fileInput("File2", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F), 
       p("Click the button to check the data was read in correctly") 
      ),   
      fixedRow(
       column(12, 
       verbatimTextOutput("errorText") 
      ) 
      )  
     ) 
     ) 
    )  
    ) 
) 

server = function(input, output,session) { 
    ## Call the error message function and print 
    output$errorText <- renderText({ 
    validate(
     need(!is.null(input$File1) 
      , 'You need to input the files before we can validate the data. Please select all the necessary files.') 
    ) 
    }) 
} 

shinyApp(ui, server) 

답변

2

UI에 두 번째로 verbatimTextOutput("errorText")이 있기 때문입니다. 샤이니에서는 그렇게 할 수 없습니다. 출력은 한 곳에서만 포함되어야합니다.

+0

감사합니다. 페이지 조건부와 페이지 조건부간에 공통된 부분을 어떻게 가질 수 있습니까? 조건부 파일 입력 아래에 각 조건에 텍스트 상자가 있어야합니까? –

+1

@ Cyrillm_44'reactive' 엘리먼트에 텍스트를 정의하고 두 개의 동일한'output $ errorText1'과'output $ errorText2'를'reactive' 엘리먼트의 값으로 렌더링 할 수 있습니다. –