问与答 r markdown-需要Pandoc 1.12.3或更高版本,但未找到(R Shiny)

pope · 2020-03-08 11:01:12 · 热度: 185

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

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

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

问题是,如果我键入$PATH,则会得到:

 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中。

服务器

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)上正常运行,但不能在服务器上运行。

预先谢谢您,如果需要,我在这里提供其他信息。

丹尼尔

猜你喜欢:
共收到 8 条回复
wowser #1 · 2020-03-08 11:01:13

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

Sys.getenv("RSTUDIO_PANDOC")

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

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

在我努力寻找rmarkdown如何找到pandoc之后,这对我有用。 我不得不检查github以查看源代码。

marion #2 · 2020-03-08 11:01:14

使该变量适用于所有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/"
mattie #3 · 2020-03-08 11:01:16

解决此问题的最简单方法是在调用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路径与非服务器版本不同)

goddard #4 · 2020-03-08 11:01:17

嘿,我刚刚打败了这个错误。 我通过从Shiny-server文件夹中删除2个pandoc文件“ pandoc”和“ pandoc-citeproc”解决了这一问题。 然后,我从rstudio-server文件夹为每个文件创建了一个链接。 它像魅力一样运作。 当我尝试在Linux机器上运行闪亮服务器时,将传单嵌入rmarkdown文档中时,这对我来说是个问题。 我发现奇怪的是,当我在同一台linux机器上的rstudio中运行它时,它可以正常工作,但是当我使用Shiny-server运行它时,它却不能正常运行。 因此,pandoc的闪亮服务器安装是旧的/过时的。干杯

gino #5 · 2020-03-08 11:01:19

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

*如果有问题,请在结尾加上/进行实验。**我无法指向UNC路径。 //在路径的开头//加上了rmarkdown包pandoc函数。 如果使用的是UNC路径,则必须将其映射到驱动器并引用驱动器号。 有一些方法可以动态地做到这一点。 我使用通过Google找到的DOS /批处理脚本。

tiago #6 · 2020-03-08 11:01:20

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

sudo pacman -S pandoc

并且有效(Arch Linux)。

oscar #7 · 2020-03-08 11:01:21

如果有人遇到此问题并且也使用anaconda,则可能是他们遇到了我的问题。 rstudio shell启动时不会加载.bashrc文件,这意味着如果在anaconda中安装了您的pandoc版本,Rstudio将找不到该文件。 使用sudo pacman -S pandoc之类的命令单独安装pandoc对我来说很有效!

lou #8 · 2020-03-08 11:01:23

我正在使用Arch Linux和RStudio。唯一对我有用的是:

sudo pacman -S pandoc

:)

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册