How can I change the name inside the downloaded file with DataTable Extensions in Shiny?

529 Views Asked by At

I have create a Shiny App where I can download my table in various file formats (pdf, excel, csv). However, I have found that each of them has the same title that my Shiny App has ("This is my table in Shiny").

I use this extension from DataTable.

Does anyone know if I can delete that title from the downloaded files?

This is how my app looks. app

These are the downloaded files (excel and pdf) excel

pdf

My code:

library(shiny)
library(DT)

ui <- fluidPage(
  
  # Application title
  titlePanel("This is my table in Shiny")
  
  , mainPanel(
    DT::dataTableOutput("fancyTable")
  ) 
  
) 

server <- function(input, output) {
  
  output$fancyTable <- DT::renderDataTable(
    datatable( data = mtcars
               , extensions = 'Buttons'
               , options = list( 
                 dom = "Blfrtip"
                 , buttons = 
                   list("copy", list(
                     extend = "collection"
                     , buttons = c("csv", "excel", "pdf")
                     , text = "Download"
                   ) ) 
                 
                
                 , lengthMenu = list( c(10, 20, -1) 
                                      , c(10, 20, "All")
                 ) 
                 , pageLength = 10
                 
                 
               ) 
               
    ) 
  )
} 

# Run the application 
shinyApp(ui = ui, server = server)

Thanks in advance

Regards

1

There are 1 best solutions below

0
On BEST ANSWER

Trying a lot of things and searching another posts... I found the solution!

I needed to put each option into a list to be able to add the "title" parameter for each one.

library(shiny)
library(DT)

ui <- fluidPage(
  
  # Application title
  titlePanel("This is my table in Shiny")
  
  , mainPanel(
    DT::dataTableOutput("fancyTable")
  ) 
  
) 

server <- function(input, output) {
  
  output$fancyTable <- DT::renderDataTable(
    datatable( data = mtcars
               , extensions = 'Buttons'
               , options = list( 
                 dom = "Blfrtip", 
                 buttons = 
                   list("copy", list(
                     extend = "collection", 
                     buttons = list(
                       list(extend = "csv", title = "MY TITLE"),
                       list(extend = "excel", title = "MY TITLE"),
                       list(extend = "pdf", title = "MY TITLE")),
                     text = "Download"
                   )),
                 
                 lengthMenu = list( c(10, 20, -1) 
                                      , c(10, 20, "All")
                 ),
                 pageLength = 10
                 
                 
               ) 
               
    ) 
  )
} 

# Run the application 
shinyApp(ui = ui, server = server)

Here you can see the new title!

image