0

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)
robdev91
  • 1,006
  • 1
  • 10
  • 18
Aimane CAF
  • 47
  • 7
  • 1
    Why don't you use my answer to your previous post? It allows to generate a true LaTeX report on clicking the button. – Stéphane Laurent Oct 22 '20 at 10:21
  • `Warning: Error in : LaTeX failed to compile C:\Users\STAGIA~1\AppData\Local\Temp\RtmpclIBQw/report.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.` The code display an error :( – Aimane CAF Oct 22 '20 at 12:58

0 Answers0