2015-02-10 210 views
25

我在從服務器上託管的應用程序中生成pdf報告時出現問題。pandoc版本1.12.3或更高版本是必需的並且未找到(R有光澤)

應用程序工作正常,但是當我按下按鈕下載報告,我得到這個錯誤:

pandoc version 1.12.3 or higher is required and was not found. 

的proble是,如果我鍵入pandoc -v我得到:

pandoc 1.12.3.3 
Compiled with texmath 0.6.6, highlighting-kate 0.5.6.1. 
Syntax highlighting is supported for the following languages: 
    actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog, 
    clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d, 
    diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang, 
    fortran, fsharp, gnuassembler, go, haskell, haxe, html, ini, java, javadoc, 
    javascript, json, jsp, julia, latex, lex, literatecurry, literatehaskell, 
    lua, makefile, mandoc, markdown, matlab, maxima, metafont, mips, modelines, 
    modula2, modula3, monobasic, nasm, noweb, objectivec, objectivecpp, ocaml, 
    octave, pascal, perl, php, pike, postscript, prolog, python, r, 
    relaxngcompact, restructuredtext, rhtml, roff, ruby, rust, scala, scheme, 
    sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, texinfo, verilog, vhdl, 
    xml, xorg, xslt, xul, yacc, yaml 
Default user data directory: /home/daniele/.pandoc 
Copyright (C) 2006-2013 John MacFarlane 
Web: http://johnmacfarlane.net/pandoc 
This is free software; see the source for copying conditions. There is no 
warranty, not even for merchantability or fitness for a particular purpose. 

所以我想我有適合的版本。 TexLive也已安裝,路徑爲$PATH

Server.R

library(shiny) 
library(drsmooth) 
library(shinyBS) 
library(knitr) 
library(xtable) 
library(rmarkdown) 

shinyServer(function(input, output,session) { 

output$downloadReport <- downloadHandler(
filename = function() { 
    paste('report', sep = '.','pdf') 
}, 

content = function(file) { 
    src <- normalizePath('report.Rmd') 

    # temporarily switch to the temp dir, in case you do not have write 
    # permission to the current working directory 
    owd <- setwd(tempdir()) 
    on.exit(setwd(owd)) 
    file.copy(src, 'report.Rmd') 

    library(rmarkdown) 
    out <- render('report.Rmd') 
    file.rename(out, file) 
}) 

output$tb <- renderUI({ 
      p(h4("Report")), 
      "Dowload a the report of your analysis in a pdf format", 
      tags$br(),downloadButton('downloadReport',label="Download report"), 
      tags$em("This option will be available soon") 
    }) 
}) 

* report.Rmd *不包含任何類型的計算,這是唯一的文本。 PDF生成在我的本地版本(MacOS)上正常工作,但不在服務器上。

在此先感謝,如果需要,我在此提供其他信息。

丹尼爾

回答

46

進入RStudio並找到RSTUDIO_PANDOC

Sys.getenv("RSTUDIO_PANDOC") 

系統環境變量然後把,在你的[R腳本之前調用渲染命令。

Sys.setenv(RSTUDIO_PANDOC="--- insert directory here ---") 

在我一直在努力尋找rmarkdown如何找到pandoc後,這對我有用。我必須檢查github才能查看源代碼。

+2

這爲我工作,而在bash中使用'export'命令沒有(我嘗試將'pandoc'目錄附加到'$ PATH'並設置'$ RSTUDIO_PANDOC')。 – knowah 2016-08-08 10:54:30

+0

如果您沒有安裝RStudio,這是否仍然有效? – user5359531 2017-01-12 18:24:21

+3

另一種選擇是將其添加到項目本地的'.Renviron'文件中'RSTUDIO_PANDOC =/usr/lib/rstudio/bin/pandoc'參考:https://csgillespie.github.io/efficientR/3-3 -R-startup.html#renviron – Interfector 2017-01-25 12:00:59

8

另一個選擇,以便這適用於所有您的R腳本是全局定義此變量。

在Debian/Ubuntu的,下面一行添加到您的.bashrc文件:

export RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc 

在MacOS,以下內容添加到你的.bash_profile文件:

export RSTUDIO_PANDOC=/Applications/RStudio.app/Contents/MacOS/pandoc