2017-02-16 9 views
0

Shiny Dashboardを開発しました。反応性のファイルリーダーなどからインポートされるデータフレームがいくつかあります。download buttonを使用して「Generate PDF」ボタンを追加しました。 )私のui.Rコードで。私のserver.Rコードは、その要求を処理するdownloadHandler()を実装しています。Shiny downloadButton()and downloadHandler()500 Error

私のWindowsデスクトップでは、これは完全に機能します。私はこれを私がセットアップしたLinuxサーバー上で動かせたいと思う。もちろん、いくつかのパスを修正しなければならず、Shiny Serverはこのボックスにrootとして実行されます。 Linuxサーバー上で実行されているサイトで「Generate PDF」ボタンをクリックすると、ほとんど瞬時にHTTP 500エラーが発生します。私は手動でLinuxサーバー上のpdfReport.Rmdファイルを手動でコンパイルしていますが、正常に動作します。私は2つのいずれか推測してい

:それは、Windowsのデスクトップ上で行うように

  1. は何とかデータは、Linuxボックスに同じように渡され取得されていません。おそらくそうは思わないかもしれませんが、それは可能です。
  2. パスに何か問題があります。一時ファイルがPDFの生成を開始するように書き込まれると、システムに能力がないか、ファイルを書き込むためのパスが存在しません。おそらく、私のdownloadHandler()コードが何らかの形で不正な形式になっている可能性があります。私はこれが#1よりも高い可能性があると思う。ここで

)(downloadHandlerための私のコードです:

output$pdfReport <- downloadHandler(
    # For PDF output, change this to "report.pdf" 
    filename = reactive({paste0("/srv/shiny-server/itpod/","ITPOD-",Sys.Date(),".pdf")}), 

    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("/srv/shiny-server/itpod", "pdfReport.Rmd") 
    file.copy("report.Rmd", tempReport, overwrite = TRUE) 

    params <- list(ilp=updateILP(), ico=updateICO(), sec=updateSecurity(), ppwc=updateWorkPreviousPeriodCompleted(), 
        pow=updateOngoingWorkCABApproved(), pwcr=updatePlannedWorkCABRequested(), epca=updateEmergencyChangesPendingCABApproval(), 
        fac=updateFacilities(), drs=updateDRStatus(), ov=updateOperationalEvents(), sl=updateStaffLocations(), 
        w = updateWeather()) 

    # 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()) 
    ) 
    } 
) 

私はパスだけで書き込み可能ではなかったので、私は、/ tmpのにそれを変更しようとしたが、それが機能しなかったということかもしれないと思いましたどちらか。

http://my.url.com:3838/itpod/session/d661a858f5679aba26692bc9b4442872/download/pdfReport?w= 

、これは問題であり、私は、もし私が疑問に始めている:チャンスをうかがっ、私は、「PDFを生成」ボタンの上に、私は「セッション」との長いURLを取得するときにすることを発見しました現在のセッションや何かのパスに書き込んでいないのですか?これはシャイニーと一緒に私に新しいエリアです。私の言ったように、私のデスクトップでは正常に動作しますが、一度Linuxサーバーに展開すれば正常に動作しません。どんな助けでも大歓迎です。前もって感謝します!

答えて

0

[OK] - 多くのトラブルシューティングの後、私は、pdfReport.Rmdファイルの依存関係であった光沢のあるWebrootにあったファイルの一部が、レポートをtempディレクトリにコピーしたので。

ウェブルートのファイルをtempにコピーしたくないので、Webルート自体の中でレポートをレンダリングすることにしました。私の場合、これは大きな問題ではありません。なぜなら、私の光沢のあるアプリは、とにかくrootとして走っているからです。

私はそれが基本的に私の修正プログラムは次の操作を実行することで、作業していることを、今、これを修正します:

  1. 通常のユーザ
  2. ではなく、ファイルのコピーなどのサービスの実行を行いますレポートは依存しているため、レポートコードでそれらを静的に参照する必要があります。

これを読んで作業しているすべての人にお詫び申し上げます。私の修正プログラムは、上記の次だったコードにした:

output$pdfReport <- downloadHandler(
     # For PDF output, change this to "report.pdf" 
     filename = reactive({paste0("/srv/shiny-server/itpod/","ITPOD-",Sys.Date(),".pdf")}), 

     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). 

     report <- file.path(getwd(), "pdfReport.Rmd") 
     #tempReport <- file.path(tempdir(), "pdfReport.Rmd") 
     #file.copy("pdfReport.Rmd", tempReport, overwrite = TRUE) 

     params <- list(ilp=updateILP(), ico=updateICO(), sec=updateSecurity(), ppwc=updateWorkPreviousPeriodCompleted(), 
         pow=updateOngoingWorkCABApproved(), pwcr=updatePlannedWorkCABRequested(), epca=updateEmergencyChangesPendingCABApproval(), 
         fac=updateFacilities(), drs=updateDRStatus(), ov=updateOperationalEvents(), sl=updateStaffLocations(), 
         w = updateWeather()) 

     # 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(report, output_file = file, params = params, envir = new.env(parent = globalenv()) 
     ) 
     } 
    ) 

    }) 

お知らせ、その代わりの一時ディレクトリにファイルをコピーし、私は現在の作業ディレクトリ内のファイルを指定します。