2017-08-23 3 views
0

ユーザーがボタンをクリックすると、データテーブルの出力をcsvに書きたいと思います。私はダウンロード機能光沢のあるダッシュボードのdownloadButton関数が機能しない

ui.r 

tabItem(tabName = "output", 
      h2("Resource Predictions"), 
      fluidRow(
       box(
       width = 3, status = "info",solidHeader = TRUE, 
       title = "QC Assignment", 
       tableOutput("qc_assign") 
      ), 
       box(
       width = 9, status = "info",solidHeader = TRUE, 
       title = "ITV Assignment", 
       DT::dataTableOutput("itv_seq") 
      )), 

      fluidRow(
      downloadButton("downloadtable", "Download ITV assignment file",style="display: block; margin: 0 auto; width: 230px;color: blue;")) 

    ), 

のためにRに次のコードを書かれていると私server.rファイルは、私がDownload ITV assignment fileボタンをクリックすると

qc_assignment <- reactive({ 
. 
. 
. 
list(ITV_assign = itv_assign) 

}) 


output$downloadtable <- downloadHandler(
itv_seq <- qc_assignment()[['ITV_assign']], 
filename = function() {paste("ITV_assignement_",input$ves_arrv_date,".csv",sep="")}, 
content = function(file){ write.csv(itv_seq, file) } 
) 

を以下のように見える、ファイルブラウザが開き、それが保存されますdownloadtableという名前のファイルで、.csv拡張子はありません。

私は間違っていますか?

答えて

0

downloadHandler指定した引数は:

downloadHandler(filename, content, contentType = NA, outputArgs = list())

私はRがあなたのitv_seq <- -Assignment remeaining引数のいずれかに一致しようとしていると思います。

output$downloadtable <- downloadHandler(
    filename = function() {  
     paste("ITV_assignement_",input$ves_arrv_date,".csv",sep="") 
    }, 
    content = function(file){ 
     itv_seq <- qc_assignment()[['ITV_assign']], 
     write.csv(itv_seq, file) 
    } 
) 

あなたは引数contentType = 'text/csv'を追加することができるが、これは、あなたが提供する拡張機能から推測されます:これは動作します。

+0

私はあなたの提案をしましたが、それでも '.csv'拡張子なしで' downloadtable'として保存しました – Neil

+0

'https:// shiny.rstudio.com/reference/shiny/latest/downloadHandler.html'あなたのために働く? – shosaco

+0

上記のリンクは存在しません。 '404 not found' – Neil

関連する問題