Commands to create a PDF file

I have a shiny app that will allow users to select inputs and is intended to produce a PDF file for printing.
The desired PDF output is not an academic style paper, so I am using Latex/Sweave to create text that wraps around figures, colored headings, etc. The text and R-chunks will reside in a Rnw file that the shiny app will call.

I cannot figure out the commands one would use to process the Rnw file and produce the PDF. As I mentioned, R markdown is too "rigid" for my needs, so I can't use this sort of construction (with the Rmd file specified below):

   output$singlePDF <- downloadHandler(
      # For PDF output, change this to "report.pdf"
      filename  <- function(){
        paste0(simpleCap(input$unit)," Community Profile ",format(Sys.Date(),"%Y%m%d"), ".pdf")
      },
      content = function(file) {
        # Copy the report file to a temporary directory before processing it, in
        # case we don't have write permissions to the current working dir (which
        # can happen when deployed).
        tempReport <- file.path(tempdir(), "Report.Rmd")
        file.copy("Report.Rmd", tempReport, overwrite = TRUE)
        
        # Set up parameters to pass to Rmd document
        
        params <- list(outChk = input$outChk,
                       listID =  idList,
                       placelist = PlaceList,
                       level = input$level,
                       curACS = curACS,
                       curYr = curYr
        )
        
        
        
        # Knit the document, passing in the `params` list, and eval it in a
        # child of the global environment (this isolates the code in the document
        # from the code in this app).
        rmarkdown::render(tempReport, output_file = file,
                          params = params,
                          envir = new.env(parent = globalenv())
        )
      }
    )  # Output singlePDF    

Is there an equivalent command to the rmarkdown:render command that will process a Rnw file?

Also, as a side question, are there any tools out there that can make rmarkdown documents more flexible?
Thanks in advance --AB

I'm wondering if you could take a fairly different approach to tackle this. Can you generate the images/charts you need and store them in a temporary directory, and then use a plain markdown document as the template where you drop the images/charts in the correct places before rendering the PDF? That would allow you to use straight HTML for some of the formatting issues you're describing (e.g., the need to float images so that text will wrap around them).

Hi Jason,
The Issues I have are slightly different. I have functions that generate the plots and tables I need (mostly ggplot2 plots and latex tables generated using kintr and kable). I have been able to output them to a PDF using r markdown. However, the output is too much like an academic paper. We need to output a document that looks like the documents here: https://demography.dola.colorado.gov/community-profiles/.

These profiles were generated using Adobe in Design. I need a system that will allow PDF documents to be produces on my server and on the fly. Nevertheless, I need much more graphic flexibility that what the r markdown route currently gives me.

How would you go about converting a HTML document to a PDF? I am open to any approach that will get me a more flexible PDF output. If there is an option that will allow me to save an HTML page as a PDF, tell me what it is and I'll give it a shot.
TIA
AB

1 Like