问题描述
我在从托管在服务器上的应用程序 Shiny 生成 pdf 报告时遇到问题.
I have a problem generating a pdf report from my app shiny which is hosted on a server.
该应用程序运行良好,但当我按下按钮下载报告时,出现此错误:
the app works fine but when I press the button to download the report, I get this error :
pandoc version 1.12.3 or higher is required and was not found.
问题是如果我输入 pandoc -v
我得到:
The proble is that if I type pandoc -v
I get:
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
中.
So I suppose I have the right version for that. TexLive is also installed and the path is in $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) 上运行良好,但在服务器上运行不正常.
* report.Rmd* does not contain any sort of calculation, it's only text.The pdf generation works fine on my local version (MacOS) but not on the server.
如果需要,我会在这里提供其他信息.
I'm here to give other information if needed.
推荐答案
进入RStudio,找到RSTUDIO_PANDOC
Go into RStudio and find the system environment variable for RSTUDIO_PANDOC
Sys.getenv("RSTUDIO_PANDOC")
然后在调用渲染命令之前将其放入 R 脚本中.
Then put that in your R script prior to calling the render command.
Sys.setenv(RSTUDIO_PANDOC="--- insert directory here ---")
在我一直在努力寻找 rmarkdown 如何找到 pandoc 之后,这对我有用.我不得不检查github以查看源.
This worked for me after I'd been struggling to find how rmarkdown finds pandoc. I had to check github to look at the source.
这篇关于需要 pandoc 1.12.3 或更高版本,但未找到(R 闪亮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!