...Is there a way to retain formatting you create in a rmarkdown document when exporting through the downloadHandler functionality? I have created an app that accepts a user input file and after they click process it will create an output. I want that output in pdf format but need to move towards our brand's fonts, colors, etc. While I can change things in the markdown file when downloading the formatting disappears. Any help would be greatly appreciated as to best approaches.
ui <- fluidPage(
tags$head(
tags$style("label{font-family: Arial;}")
),
tabPanel("Proposed Lineups",
fluidRow(
column(6,
tags$br(),
fileInput("lineups","Select Input File",
accept = c(".csv",".xlsx")),
radioButtons(inputId = 'filetype',label = 'Choose Ticker File Type:',
choices = list('CSV ','XLSX'), inline = TRUE)
),
column(6,
tags$br(),
tags$br(),
actionButton("golineup","Create Proposal Summary:",class = "butt"),br(),
tags$head(tags$style(".butt{background-color:rgb(85,114,138);} .butt{color: #e6ebef;}")),
tags$br(),
tags$br(),
downloadButton('describe_download',"Download Report",class="butt" ),br(),
tags$head(tags$style(".butt{background-color:rgb(85,114,138);} .butt{color: #e6ebef;}")),
radioButtons('format', 'Document format', c('Word','PDF'),
inline = TRUE)
)
),
fluidRow(style = "border-bottom: 6px solid; border-color: rgb(85,114,138)",
tags$br()
),
fluidRow(
tags$br()
),
DT::dataTableOutput("Lineups")))
server <- function(input,output,session){
#Download the Final Output
output$describe_download = downloadHandler(
filename<- function(){
paste("Summary",Sys.Date(),switch(
input$format, PDF = '.pdf', Word = '.docx'
),sep = "")
},
content = function(file) {
if (input$format=="PDF"){
#### Progressing indicator
withProgress(message = 'Download in progress',
detail = 'This may take a while...', value = 0, {
for (i in 1:15) {
incProgress(1/15)
Sys.sleep(0.01)
}
## End of progression
src <- normalizePath("S:/Aaron/R/Apps/Sample Illustrative Lineup Application/summary_PDF.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,"summary_PDF.Rmd", overwrite = TRUE)
library(rmarkdown)
out <- render("summary_PDF.Rmd", pdf_document())
file.rename(out, file)
})
### below is the end of pdf content
}else{
withProgress(message = 'Download in progress',
detail = 'This may take a while...', value = 0, {
for (i in 1:15) {
incProgress(1/15)
Sys.sleep(0.01)
}
## End of progression
src <- normalizePath('S:/Aaron/R/Apps/Sample Illustrative Lineup Application/summary_word.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, 'summary_word.Rmd', overwrite = TRUE)
library(rmarkdown)
out <- render('summary_word.Rmd', word_document())
file.rename(out, file)
})
}
})
}
shinyApp(ui = ui, server = server)
#Markdown file I am feeding
---
title: "Sample Proposal -"
author: "`XXXXX`"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
pdf_document:
latex_engine: xelatex
mainfont: Arial
allow_html: yes
---
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
## Proposal Summary
Some text goes here
Code will go below