I want to customize my PDF output by :
- Centering my data table
- Enlarging logo
- Writing Data Extraction below the logo
- Making the table pretty
I think that we need to work with JavaScript to solve this kind of problem, if anyone knows how to do so, please tell me
Thank you so much for your collaboration!
library(shiny)
library(DT)
library(base64enc)
ui <- fluidPage(
tags$head(
tags$script(src = "https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"),
tags$script(src = "https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js")
),
br(),
DTOutput("dtable")
)
server <- function(input, output, session){
output[["dtable"]] <- renderDT({
datatable(
iris[1:5,],
extensions = "Buttons",
options = list(
dom = "Bfrtip",
buttons = list(
list(
extend = "pdfHtml5",
customize = JS(
"function(doc) {",
" doc.content.splice( 1, 0, {",
" margin: [ 0, 0, 0, 12 ],",
" alignment: 'center',",
sprintf(
" image: '%s',",
dataURI(
file = "https://www.r-project.org/logo/Rlogo.png",
mime = "image/png"
)
),
" width: 50",
" })",
"}"
)
)
)
)
)
})
}
shinyApp(ui, server)