2017-12-10 12 views
1

私はマルチタブアプリケーションにしようとしています。私は第2タブのページレイアウトを最初のパネルからの入力に条件付きにします。基本的には、最初のパネルの値が1の場合、ユーザーが最初のパネルに値2を入力した後、2番目のパネルに2つのファイル入力を表示させたい場合は、現在のところ、私のコードでは両方の条件が表示されていますが、わかりません。以下の再現可能なコードを参照してください。あなたのUIで二回verbatimTextOutput("errorText")を持っているためだ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

。あなたはシャイニーでそれをすることはできません。出力は1か所にのみ含まれなければなりません。

+0

ありがとうございました。私は、ページの一部を条件付きで、ページの一部を条件間で共通化する方法を教えてください。私は条件ファイルの入力の下にテキストボックスを持つように各条件をしたいですか? –

+1

@ Cyrillm_44 'reactive'要素にテキストを定義して、' reactive $ errorText1'と 'output $ errorText2'という2つの同一の' react'要素の値をレンダリングするだけです。 –

関連する問題