2
votes

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.

Any help is greatly apreciated.

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;
  }
}
1
I took your reproducible example, switched it over to separate ui.R and server.R files, and put it on shinyapps.io here. It seems to work fine. Perhaps the problem is with your installation of shiny server? You might want to try removing and reinstalling the relevant packages.Paul de Barros
@PauldeBarros: Unfortunately that doesn't help. The problem persists after separating the app into ui.R and server.R.Christoph Scholz
Do you have another installation of shiny server somewhere? If so, you could try testing it on that. Since it runs on shinyapps.io, it seems like it should on shiny server in general. I updated the shinyapps.io version to show the sessioninfo(). Interestingly, it does not show leaflet in the "loaded via namespace" list.Paul de Barros
I actually reinstalled one server from scratch an tried it also on another server. Both are running CentOS 7 though.Christoph Scholz
Interesting. I found a few examples of someone saying that they were unable to install the leaflet package for R on a Centos machine. ex1 ex2. This sounds like a different, but possibly related, problem. Unfortunately, I don't know enough about Centos or leaflet to help.Paul de Barros

1 Answers

0
votes

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.