Shiny Download does not execute R code

I am currently trying to create a downloadable report within a Shiny app. The download renders correctly, but none of the code is being executed. Running rmarkdown::render() with the same parameters works perfectly fine, but within the Shiny app it is only displaying text.

Below is the shiny server code:

server <- function(input, output) {
  output$publicreport <- downloadHandler(
          filename = "report.pdf",
          content = function(file) {
              tempReport <- file.path(tempdir(), "report.pdf")
              file.copy(here::here("report.Rmd"), tempReport, overwrite = TRUE)
  
              rmarkdown::render(
                  tempReport,
                  output_file = file,
                  envir = new.env(parent = globalenv())
              )
          }
      )
}

The report.Rmd file is the default rMarkdown document. The output looks correct, but does not execute any code or rather can't correctly identify the code blocks as R code. I've attached a photo of the pdf output.

image

Any help is appreciated

sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

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

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

loaded via a namespace (and not attached):
[1] compiler_4.2.0 tools_4.2.0    renv_0.15.5   
> library(rmarkdown)
> library(shiny)
> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

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

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

other attached packages:
[1] shiny_1.7.2      rmarkdown_2.16.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9       digest_0.6.29    later_1.3.0      mime_0.12       
 [5] R6_2.5.1         lifecycle_1.0.2  xtable_1.8-4     magrittr_2.0.3  
 [9] evaluate_0.15    rlang_1.0.6      cli_3.4.1        renv_0.15.5     
[13] promises_1.2.0.1 ellipsis_0.3.2   tools_4.2.0      httpuv_1.6.6    
[17] xfun_0.31        fastmap_1.1.0    compiler_4.2.0   htmltools_0.5.3 
[21] knitr_1.39      

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.