Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
How to add space on the left and right of a table exported to a PDF with datatable in shiny?

I want to export a table displayed in a shiny app using datatable to a PDF. For this purpose, I am using the export button provided by datatable, see the code below.

However, I want to make a little modification to the table shown in the PDF. I want to add some space to the left of the first column and to the right of the last column.

I couldn't find a datatable option to control this. It seems, I have to use the pdfmake library to specify this via the customize argument. You can see something I tried in the code below, however commented out, as it does not work. I tried a lot of other stuff but nothing worked. Unfortunately, I have almost no experience with JavaScript, that's why I hope someone can help me here.

library(shiny)
library(DT) 

words <- c("water", "apple", "house", "family", "basket")
set.seed(42)
data <- data.frame(column1 = sample(words, 10, TRUE), 
                   column2 = sample(words, 10, TRUE), 
                   column3 = sample(words, 10, TRUE))

ui <- fluidPage(
  DTOutput("dtable")
)

server <- function(input, output, session) {
  output$dtable <- renderDT({
    datatable(data, 
              rownames = FALSE, 
              extensions = "Buttons", 
              options = list(
                dom = "Bfrtip", 
                buttons = list(
                  list(
                    extend = "pdf", 
                    exportOptions = list(orthogonal = "export"), 
                    filename = "Filename", 
                    title = "Title", 
                    # customize = JS("function(doc) { doc.content.table.margin = [50, 0, 50, 0]; }")
                    orientation = "landscape")
                )
              )
    )
  })
}

shinyApp(ui, server)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda