2017-04-12 21 views
1

shtmlのhtml/pdfファイルをエクスポートしたいのですが、これが見つかりました https://shiny.rstudio.com/articles/generating-reports.htmlです。R Shiny - 生成レポート

library(shiny) 

server <- function(input, output) { 
     output$report <- downloadHandler(
    # For PDF output, change this to "report.pdf" 
     filename = "report.html", 
     content = function(file) { 
    # Copy the report file to a temporary directory before processing it, in 
    # case we don't have write permissions to the current working dir (which 
    # can happen when deployed). 
     tempReport <- file.path(tempdir(), "report.Rmd") 
     file.copy("report.Rmd", tempReport, overwrite = TRUE) 

    # Set up parameters to pass to Rmd document 
     params <- list(n = input$slider) 

    # Knit the document, passing in the `params` list, and eval it in a 
    # child of the global environment (this isolates the code in the document 
    # from the code in this app). 
     rmarkdown::render(tempReport, output_file = file, 
      params = params, 
      envir = new.env(parent = globalenv()) 
     )})} 

ui <- fluidPage(
    sliderInput("slider", "Slider", 1, 100, 50), 
    downloadButton("report", "Generate report")) 

shinyApp(ui = ui, server = server) 

しかし、私はレポート(失敗したサーバーの問題)をダウンロードして、エラーを得たことができません:

は、その後、私は打撃を示している。このウェブサイトからコードを使用しようとした

Listening on http://127.0.0.1:3638 
Warning in normalizePath(path, winslash = winslash, mustWork = mustWork) : 
    path[1]="/tmp/Rtmp1BbjoR/test.Rmd": No such file or directory 
Warning: Error in tools::file_path_as_absolute: file '/tmp/Rtmp1BbjoR/test.Rmd' does not exist 
Stack trace (innermost first): 
    58: tools::file_path_as_absolute 
    57: dirname 
    56: setwd 
    55: rmarkdown::render 
    54: download$func [example_code/report.R#23] 
    5: <Anonymous> 
    4: do.call 
    3: print.shiny.appobj 
    2: print 
    1: print 
Error : file '/tmp/Rtmp1BbjoR/test.Rmd' does not exist 

私はRサーバーで作業しています。このエラーに関して何か提案はありますか?

ありがとうございます。

+0

'file.copy'はレポートを一時フォルダにコピーしないようです。レポートが現在のディレクトリ 'print(getwd())にあることを確認してください。 – HubertL

+0

ありがとう@HubertL、私はカレントディレクトリに空白のレポートファイルを作成しました。しかし、私がダウンロードしたレポートはまだ空白のレポートです。上書き引数が機能しないようですか?ありがとう! – hualahualaqqq

+0

私はあなたの問題を理解しているとは思わない:空白のレポートを作成する空白のレポートを生成する期待どおりに私に聞こえます – HubertL

答えて

0

骨格.Rmd(目に見えない.txt内線を避けるために、好ましくはRスクリプトとして作成し、report.Rmd命名。)ファイルが作業ディレクトリに存在する必要があり、ウェブサイト上の例を再作成します。このシェルファイルの内容は、この質問で参照されているWebページに示されています。だから、手順は次のとおりです。

  1. は述べてWebページからの内容で、ファイル、report.Rmdを作成します。拡張子が.txtではないことを確認してください。

  2. Rセッションの作業ディレクトリに配置します。

  3. コードをそのまま実行してください。