2016-03-30 16 views
0

tabsetPanel内の2つのタブを切り替えるたびに、fileInputコントロールをリセットする必要があります。Shiny RのtabsetPanel内のタブの切り替え時のfileInputコントロールのクリア

私はこのトピックに関する既存の質問を参照しましたが、私のニーズに合わせることができませんでした。 how can I update a shiny fileInput object?

クリアボタンやリフレッシュボタンはありません。タブのスイッチでこれを行う必要があります。その逆と -

は、以下の「FixedwidthTab」と呼ばれる最初のタブの中にファイルをアップロードしてから、「DelimitedTab」と呼ばれる2番目のタブに切り替えることができ

fluidPage(
    fluidRow(column(width=10, 
    tabsetPanel(id="tabPanelOptions", 
     tabPanel(value="FixedwidthTab", "Fixed width", 
     br(), 
     fluidRow(column(width=12, fileInput('layoutfile', 'Upload Excel file to define layout', accept = '.xlsx'))) 
    ), 
     tabPanel(value="DelimitedTab", "Delimited", 
     br(), 
     fluidRow(column(width=5, textInput("separator", "Field separator:",","))), 
     fluidRow(
      column(width=5, checkboxInput("quotes","Quoted texts?",FALSE)), 
      column(width=5, checkboxInput("header","Files contains header (column names)",FALSE)) 
     ), 
     fluidRow(column(width=10, textInput("expcolumns", "Expected variables in file","27"))), 
     fluidRow(column(width=10, fileInput('headerfile', '(Optional) Upload CSV file to define attribute names', accept = c('text/csv','text/comma-separated-values', 'text/tab-separated-values', 'text/plain','.csv','.txt')))), 
     br(), 
     fluidRow(
      column(width=5,conditionalPanel(condition= "input.header == false",uiOutput("choose_columns"))), 
      column(width=5,conditionalPanel(condition= "input.header == false", uiOutput("rename_columns")))) 
     ) 
    ) 
    ) 
) 
) 

ユーザーの私ui.Rです。両方のタブにはfileInputコントロールがあり、タブの切り替え時にそれらをリセットする必要があります。

答えて

0

これはあなたのために働くでしょうか?私はfileInputsを、サーバーサイドでレンダリングされたUIと交換しました。これは、対応するタブが選択されているときはいつでもfileInputsを再描画します。

以下のコードを参照してください:

shinyApp(
    ui = shinyUI(
    fluidPage(
     fluidRow(column(width=10, 
     tabsetPanel(id="tabPanelOptions", 
      tabPanel(value="FixedwidthTab", "Fixed width", 
      br(), 
      fluidRow(column(width=12, uiOutput("file1"))) 
     ), 
      tabPanel(value="DelimitedTab", "Delimited", 
      br(), 
      fluidRow(column(width=5, textInput("separator", "Field separator:",","))), 
      fluidRow(
       column(width=5, checkboxInput("quotes","Quoted texts?",FALSE)), 
       column(width=5, checkboxInput("header","Files contains header (column names)",FALSE)) 
      ), 
      fluidRow(column(width=10, textInput("expcolumns", "Expected variables in file","27"))), 
      fluidRow(column(width=10, uiOutput("file2"))), 
      br(), 
      fluidRow(
       column(width=5,conditionalPanel(condition= "input.header == false",uiOutput("choose_columns"))), 
       column(width=5,conditionalPanel(condition= "input.header == false", uiOutput("rename_columns"))) 
      ) 
     ) 
     ) 
    )) 
    ) 
), 

    server = function(input, output){ 

    output$file1 <- renderUI({ 
     if(input$tabPanelOptions == "FixedwidthTab"){ 
     fileInput('layoutfile', 'Upload Excel file to define layout', accept = '.xlsx') 
     } 
    }) 

    output$file2 <- renderUI({ 
     if(input$tabPanelOptions == "DelimitedTab"){ 
     fileInput('headerfile', '(Optional) Upload CSV file to define attribute names', 
     accept = c('text/csv','text/comma-separated-values','text/tab-separated-values', 
     'text/plain','.csv','.txt')) 
     } 
    }) 

    } 
) 

をご提供答えについて質問がある場合は、お問い合わせください!

関連する問題