rshinyr-markdownshiny-serverr-leaflet

shiny app with downloadable md report, error: "pandoc: Could not find data file" when run by shiny-server


I created a shiny app that provides a download button. When pressed, a markdown report is created in html-format. Here is the app:

server <- function(input, output) {
  output$report <- downloadHandler(
    filename = "report.html",
    content = function(file){
      tempReport <- file.path(tempdir(), "report.Rmd")
      file.copy("report.Rmd", tempReport, overwrite = TRUE)
      out <- rmarkdown::render(tempReport, output_file = file)
    }
  )
}

ui <- fluidPage(
  downloadButton("report", label=NULL)
)

shinyApp(ui = ui, server = server)

report.Rmd looks like this:

---
output: html_document
---
## Hello
```{r map}
leaflet::leaflet()
```

If I run the app from rstudio-server evrything works fine: A standalone html-file is created and downloaded. It includes the leaflet map.

However if I run it from shiny-server all I get is the following error:

processing file: report.Rmd
output file: report.knit.md

pandoc: Could not find data file /usr/lib64/R/library/leaflet/htmlwidgets/lib/leaflet/
Warnung: Error in : pandoc document conversion failed with error 97
Stack trace (innermost first):
    53: pandoc_convert
    52: convert
    51: rmarkdown::render
    50: download$func [/srv/shiny-server/biserver/downReport/app.R#7]
     1: runApp
Error : An error has occurred. Check your logs or contact the app author for clarification.

The error seems to be triggered by combining rmarkdown, shiny-server and leaflet. Removing leaflet from the report for example fixes it.

Here is my output from sessionInfo():

R version 3.3.3 (2017-03-06)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

locale:
 [1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C               
LC_TIME=de_DE.UTF-8        LC_COLLATE=de_DE.UTF-8    
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=de_DE.UTF-8    
LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             
LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.0.3

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10    digest_0.6.12   rprojroot_1.2   mime_0.5        
R6_2.2.1        xtable_1.8-2    jsonlite_1.4   
 [8] backports_1.0.5 magrittr_1.5    evaluate_0.10   stringi_1.1.5   
leaflet_1.1.0   rmarkdown_1.5   tools_3.3.3    
[15] stringr_1.2.0   htmlwidgets_0.8 crosstalk_1.0.0 yaml_2.1.14     
httpuv_1.3.3    htmltools_0.3.6 knitr_1.15.1   

I am using Shiny Server v1.5.3.838 (Node.js v6.10.0). This is my shiny-server.conf:

run_as shiny;
# Define a server that listens of port 3839.
server {
   listen 3839;

  location / {
     site_dir /srv/shiny-server/biserver;
     log_dir /var/log/shiny-server;
  }
}

Solution

  • Same problem here... Solved.

    The shiny-server and rstudio server has a pandoc embedded on installation directory.

    Just remove the bad pandoc binary file of shiny server and do a logical link in the same location to a new pandoc version or, in my case, I used the pandoc version of a local rstudio server that is working.