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

12

85

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.

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.

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* 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.

Lupitalupo answered 10/2, 2015 at 13:13 Comment(0)
W
136

Go into RStudio and find the system environment variable for RSTUDIO_PANDOC

Sys.getenv("RSTUDIO_PANDOC")

Then put that in your R script prior to calling the render command.

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

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.

Writeup answered 17/4, 2015 at 22:46 Comment(5)
This worked for me, whereas using the export command in bash did not (I tried both appending the pandoc directory to $PATH and setting the $RSTUDIO_PANDOC).Awed
Does this still work if you do not have RStudio installed?Matthias
Yet another option is to add this to an .Renviron file local to your project RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc Ref: csgillespie.github.io/efficientR/3-3-r-startup.html#renvironMariano
One can use which pandoc in the terminal to find where pandoc is, and then put this in the .Renviron using usethis::edit_r_environ().Whimper
To add specificity: use rmarkdown::find_pandoc()Dietary
A
19

Another option so that this works for all your R scripts is to define this variable globally.

On Debian/Ubuntu, add the following line to your .bashrc file:

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

On macOS, add the following to your .bash_profile file:

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

On Windows (using Git Bash), add the following to your .bashrc file:

export RSTUDIO_PANDOC="/c/Program Files/RStudio/bin/pandoc/"
Amoritta answered 8/4, 2016 at 4:57 Comment(0)
H
13

The easiest way I solved this issue is to pass the Sys.setenv(..) command inside the crontab command prior to calling the RMarkdown::render. You need to separate the two commands with a semicolon:

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

(Remember that the rstudio-server path differs from the non-server version)

Hyperkeratosis answered 18/6, 2018 at 15:55 Comment(0)
A
4

I'm using Arch Linux, and RStudio as well.. the only thing that worked for me was:

sudo pacman -S pandoc

:)

Afroasian answered 13/9, 2019 at 4:54 Comment(1)
Here are some guidelines for How do I write a good answer?. This provided answer may be correct, but it could benefit from an explanation.Vastitude
G
4

For Windows 10, RStudio 2022.12.0

Pandoc is installed with RStudio, so I prefer to use the already-installed pandoc.exe. As far as I can tell where it is installed changes from time to time. In the last couple of years, I've seen it in the below locations (the top one is where it is with my current verison of RStudio).

January 2023- "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools"
August 2022- "C:/Program Files/RStudio/bin/quarto/bin/tools"
"C:/Program Files/RStudio/bin/quarto/bin"
"C:/Program Files/RStudio/bin/pandoc"

Once you know where the pre-installed pandoc is you can include this line in your .R file as the top answer from Chris/Yihui indicate and it works for me.

Sys.setenv(RSTUDIO_PANDOC = "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools")
Germaine answered 4/8, 2022 at 18:26 Comment(0)
T
3

For those not using RStudio, you may just need to install pandoc on your system. For me it was

sudo pacman -S pandoc

and it worked (Arch Linux).

Tyrannize answered 27/6, 2018 at 21:53 Comment(0)
C
2

If anyone is having this issue and also use anaconda, its possible they were having my issue. The rstudio shell does not load the .bashrc file when it starts up meaning if your version of pandoc is installed within anaconda Rstudio will not find it. Installing pandoc separately with a command like sudo pacman -S pandoc worked for me!

Coverage answered 27/1, 2019 at 23:23 Comment(0)
A
2

I had a similar problem with pandoc on Debian 10 while building a bookdown document. In the Makefile what I did was:

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

These two rules are equivalent and knit the book successfully.

I just didn't like the long Rscript command:

Rscript -e "Sys.setenv(RSTUDIO_PANDOC='/usr/lib/rstudio/bin/pandoc'); bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
Anderton answered 29/10, 2020 at 3:17 Comment(0)
F
1

If you are trying to run a script from the command line on Windows you just need to have the directory path in the PATH variable*. You can also create a separate User variable named RSTUDIO_PANDOC and give this variable the directory*. Then close and reopen any terminals to refresh the system paths.**

*Experiment with a trailing / if you are having issues. **I was unable to point to a UNC path. The // at the beginning of the path hosed the rmarkdown package pandoc functions. If you are using a UNC path, you must map it to a drive and reference the drive letter. There are ways to do this dynamically. I use a DOS/batch script which I found via Google.

Footsore answered 20/4, 2018 at 20:14 Comment(0)
A
1

Hey I just beat this error. I solved this by deleting the 2 pandoc files, "pandoc" and "pandoc-citeproc" from the shiny-server folder. I then created a link for each of these files from the rstudio-server folder. It worked like a charm. This was an issue for me when I was trying to embed leaflet in the rmarkdown documents from running a shiny-server on a linux machine. I found it odd that when I ran it in rstudio on the same linux machine it worked fine, but not when I ran it using shiny-server. So the shiny-server install of pandoc is old/outdated. Cheers

Aliform answered 30/4, 2018 at 6:3 Comment(0)
S
1

On Windows, and without RStudio, you can install pandoc with choco install pandoc or via the pandoc website, https://pandoc.org/.

Make sure to restart your IDE to ensure it picks up the new install.

Syzran answered 9/4, 2021 at 20:17 Comment(0)
S
0

I was facing a similar issue in IntelliJ R plugin. I solved it by copying the pandoc file in ~/.IntelliJIdea2019.3/config/plugins/rplugin/pandoc

Scudder answered 1/2, 2020 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.