簡體   English   中英

如何使用 Shiny 中的 DataTable Extensions 更改下載文件中的名稱?

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

我創建了一個 Shiny 應用程序,我可以在其中下載各種文件格式的表格(pdf、excel、csv)。 但是,我發現它們每個都具有與我的 Shiny 應用程序相同的標題(“這是我在 Shiny 中的表”)。

我使用 DataTable 中的這個擴展

有誰知道我是否可以從下載的文件中刪除該標題?

這就是我的應用程序的外觀。 應用程序

這些是下載的文件(excel和pdf) 擅長

pdf

我的代碼:

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)

提前致謝

問候

嘗試了很多東西並搜索了其他帖子......我找到了解決方案!

我需要將每個選項放入一個列表中,以便能夠為每個選項添加“標題”參數。

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)

在這里你可以看到新的標題!

圖片

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM