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

时间:2015-02-10 13:13:53

标签: pandoc r-markdown shiny-server

我在我的应用程序闪亮生成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)上运行正常但在服务器上没有。

提前致谢,如果需要,我会在此提供其他信息。

丹尼尔

11 个答案:

答案 0 :(得分:76)

进入RStudio并找到RSTUDIO_PANDOC

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

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

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

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

答案 1 :(得分:10)

另一个适用于所有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/"

答案 2 :(得分:4)

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

答案 3 :(得分:1)

嘿,我刚刚击败了这个错误。我通过删除2个pandoc文件来解决这个问题,&#34; pandoc&#34;和&#34; pandoc-citeproc&#34;来自shiny-server文件夹。然后,我从rstudio-server文件夹为每个文件创建了一个链接。它就像一个魅力。当我试图在Linux机器上运行闪亮服务器的rmarkdown文件中嵌入传单时,这对我来说是一个问题。我发现奇怪的是,当我在同一台Linux机器上的rstudio中运行它时工作得很好,但是当我使用闪亮服务器运行时却没有。所以pandoc的闪亮服务器安装已经过时/过时了。 干杯

答案 4 :(得分:1)

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

sudo pacman -S pandoc

:)

答案 5 :(得分:0)

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

*尝试使用尾随/如果您遇到问题。 **我无法指向UNC路径。在路径开头的//给出了rmarkdown包的pandoc函数。如果您使用的是UNC路径,则必须将其映射到驱动器并引用驱动器号。有一些方法可以动态地执行此操作。我使用的是我通过谷歌发现的DOS /批处理脚本。

答案 6 :(得分:0)

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

sudo pacman -S pandoc

并且有效(Arch Linux)。

答案 7 :(得分:0)

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

答案 8 :(得分:0)

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

中复制pandoc文件来解决此问题

答案 9 :(得分:0)

在构建书本文档时,在Debian 10上<template> <div> <div class="container"> <form @submit.prevent="handleSubmit"> <div class="form-group"> <input type="file" @change="uploadFile" /> </div> <div class="form-group"> <button class="btn btn-success btn-block btn-lg">Upload</button> </div> </form> </div> </div> </template> <script> import axios from "axios"; export default { data() { return { file: null, }; }, methods: { uploadFile(event) { this.file = event.target.files[0]; }, handleSubmit() { const formData = new FormData(); formData.append("container", "image"); formData.append("publisher", "jim"); formData.append("grade", "9"); formData.append("version", "v1"); formData.append("stage", "pub"); formData.append("subject", "test"); formData.append("file", this.file, { type: "*/*" }); axios .post("", formData, { headers: { "Content-Type": "multipart/form-data" }, }) .then((res) => { console.log(res.statusText); }) .catch((err) => { console.log(err); throw err; }); }, }, }; </script> <style scoped lang="scss"> .container { max-width: 600px; } </style> 遇到了类似的问题。在const blobName = (req, file) => { console.log(req.body); const publisher = req.body.publisher; const grade = req.body.grade; const subject = req.body.subject; const version = req.body.version; const stage = req.body.stage; const check = req.body.container; let blobName = ""; if (check === "image") { blobName = publisher + "/" + grade + "/" + subject + "/" + "version" + version; } else { blobName = publisher + "/" + grade + "/" + subject + "/" + version + "/" + "stage_" + stage; } console.log("The blob name :" + blobName); return blobName; }; const containerName = (req, file) => { console.log(req.body); const containerName = req.body.container; return containerName; }; const azureStorage = new MulterAzureStorage({ accessKey: accessKey, accountName: accountName, containerName, blobName, containerAccessLevel: "blob", urlExpirationTime: 60, }); const upload = multer({ storage: azureStorage, }); router.post("/upload", upload.any(), (req, res, next) => { res.send("ok"); }); 中,我所做的是:

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')"

答案 10 :(得分:0)

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

确保重新启动您的 IDE 以确保它接受新安装。