pandoc版本1.12.3或更高版本是必需的,没有找到(R闪亮)

Dan*_*ini 48 pandoc r-markdown shiny-server

我从我的应用程序闪亮生成pdf报告时遇到问题,该报告托管在服务器上.

该应用程序工作正常,但当我按下按钮下载报告时,我收到此错误:

 pandoc version 1.12.3 or higher is required and was not found.
Run Code Online (Sandbox Code Playgroud)

问题是,如果我输入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.
Run Code Online (Sandbox Code Playgroud)

所以我想我有正确的版本.还安装了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")
     })
})
Run Code Online (Sandbox Code Playgroud)

*report.Rmd*不包含任何类型的计算,它只是文本.pdf生成在我的本地版本(MacOS)上运行正常,但在服务器上运行不正常.

在此先感谢,如果需要,我在这里提供其他信息.

丹尼尔

小智 81

进入RStudio并找到系统环境变量 RSTUDIO_PANDOC

Sys.getenv("RSTUDIO_PANDOC")
Run Code Online (Sandbox Code Playgroud)

然后在调用render命令之前将其放入R脚本中.

Sys.setenv(RSTUDIO_PANDOC="--- insert directory here ---")
Run Code Online (Sandbox Code Playgroud)

在我努力寻找rmarkdown如何找到pandoc后,这对我有用.我必须检查github来查看源代码.

  • 另一个选择是将它添加到项目本地的`.Renviron`文件中`RSTUDIO_PANDOC =/usr/lib/rstudio/bin/pandoc`参考:https://csgillespie.github.io/efficientR/3-3- R-startup.html#renviron (4认同)
  • 这对我有用,而在bash中使用`export`命令却没有(我尝试将`pandoc`目录附加到`$ PATH`并设置`$ RSTUDIO_PANDOC`). (2认同)
  • 如果您没有安装 RStudio,这仍然有效吗? (2认同)

Joh*_*hak 11

另一个选项是这个适用于所有R脚本的选项是全局定义此变量.

在Debian/Ubuntu上,将以下行添加到.bashrc文件中:

export RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
Run Code Online (Sandbox Code Playgroud)

在macOS上,将以下内容添加到.bash_profile文件中:

export RSTUDIO_PANDOC=/Applications/RStudio.app/Contents/MacOS/pandoc
Run Code Online (Sandbox Code Playgroud)

在Windows上(使用Git Bash),将以下内容添加到.bashrc文件中:

export RSTUDIO_PANDOC="/c/Program Files/RStudio/bin/pandoc/"
Run Code Online (Sandbox Code Playgroud)


小智 5

解决此问题的最简单方法是在调用RMarkdown :: render之前在crontab命令中传递Sys.setenv(..)命令。您需要用分号分隔两个命令:

R -e "Sys.setenv(RSTUDIO_PANDOC='/usr/lib/rstudio-server/bin/pandoc'); rmarkdown::render('File.Rmd', output_file='output.html')"
Run Code Online (Sandbox Code Playgroud)

(请记住,rstudio-server路径与非服务器版本不同)