pandoc 版本 1.12.3 或更高版本是必需的,但未找到 (R shiny)

pandoc version 1.12.3 or higher is required and was not found (R shiny)

我在从托管在服务器上的应用程序 shiny 生成 pdf 报告时遇到问题。

该应用程序运行正常,但是当我按下按钮下载报告时,出现此错误:

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

问题是,如果我输入 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) 上运行良好,但在服务器上运行不正常。

如果需要,我可以提供其他信息。

进入 RStudio 并找到 RSTUDIO_PANDOC

的系统环境变量
Sys.getenv("RSTUDIO_PANDOC")

然后在调用渲染命令之前将其放入 R 脚本中。

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

在我一直在努力寻找 rmarkdown 如何找到 pandoc 之后,这对我有用。我必须检查 github 才能查看来源。

另一种适用于所有 R 脚本的方法是全局定义此变量。

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

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

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

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

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

export RSTUDIO_PANDOC="/c/Program Files/RStudio/bin/pandoc/"

如果您尝试从 Windows 上的命令行 运行 脚本,您只需要在 PATH 变量中包含目录路径*。您还可以创建一个名为 RSTUDIO_PANDOC 的单独用户变量,并为该变量指定目录*。然后关闭并重新打开任何终端以刷新系统路径。**

*如果遇到问题,请尝试使用尾随 /。 **我无法指向 UNC 路径。路径开头的 // 包含 rmarkdown 包 pandoc 函数。如果您使用的是 UNC 路径,则必须将其映射到驱动器并引用驱动器号。有一些方法可以动态地做到这一点。我使用通过 Google.

找到的 DOS/batch 脚本

嘿,我刚刚克服了这个错误。我通过从 shiny-server 文件夹中删除 2 个 pandoc 文件 "pandoc" 和 "pandoc-citeproc" 来解决这个问题。然后,我为 rstudio-server 文件夹中的每个文件创建了一个 link。它就像一个魅力。当我试图在 linux 机器上的 运行 闪亮服务器的 rmarkdown 文档中嵌入传单时,这对我来说是个问题。我发现奇怪的是,当我 运行 它在同一台 linux 机器上的 rstudio 中它工作正常,但当我 运行 它使用 shiny-server 时却没有。所以 pandoc 的 shiny-server 安装是 old/outdated。 干杯

我解决这个问题的最简单方法是在调用 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')"

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

对于那些不使用 RStudio 的人,您可能只需要在您的系统上安装 pandoc。对我来说是

sudo pacman -S pandoc

并且成功了(Arch Linux)。

如果有人遇到这个问题并且还使用 anaconda,那么他们可能遇到了我的问题。 rstudio shell 启动时不会加载 .bashrc 文件,这意味着如果你的 pandoc 版本安装在 anaconda 中,Rstudio 将找不到它。使用像 sudo pacman -S pandoc 这样的命令单独安装 pandoc 对我有用!

我正在使用 Arch Linux,还有 RStudio.. 唯一对我有用的是:

sudo pacman -S pandoc

:)

我在 IntelliJ R 插件中遇到了类似的问题。我通过复制 ~/.IntelliJIdea2019.3/config/plugins/rplugin/pandoc

中的 pandoc 文件解决了这个问题

我在 Debian 10 上构建 bookdown 文档时遇到了与 pandoc 类似的问题。在 Makefile 中,我所做的是:

# use rstudio pandoc
# this rule sets the PANDOC environment variable from the shell
build_book1:
    export RSTUDIO_PANDOC="/usr/lib/rstudio/bin/pandoc";\
    Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::gitbook")'

# use rstudio pandoc
# this rule sets the environment variable from R using multilines
build_book2:
    Rscript -e "\
    Sys.setenv(RSTUDIO_PANDOC='/usr/lib/rstudio/bin/pandoc');\
    bookdown::render_book('index.Rmd', 'bookdown::gitbook')"

这两条规则等价,编织成功

我只是不喜欢长 Rscript 命令:

Rscript -e "Sys.setenv(RSTUDIO_PANDOC='/usr/lib/rstudio/bin/pandoc'); bookdown::render_book('index.Rmd', 'bookdown::gitbook')"

在 Windows 上,如果没有 RStudio,您可以使用 choco install pandoc 或通过 pandoc 网站 https://pandoc.org/.

安装 pandoc

请务必重新启动您的 IDE 以确保它能够进行新安装。