r - 如何在 Shiny 中使用 DataTable Extensions 更改下载文件中的名称?
问题描述
我创建了一个闪亮的应用程序,我可以在其中下载各种文件格式(pdf、excel、csv)的表格。但是,我发现它们中的每一个都具有与我的 Shiny 应用程序相同的标题(“这是我在 Shiny 中的表”)。
我使用 DataTable 中的这个扩展。
有谁知道我是否可以从下载的文件中删除该标题?
我的代码:
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)
在这里你可以看到新的标题!
推荐阅读
- jquery - 使用 QUnit 测试表单是否提交了两次
- sql - 如何自动杀死活动会话?
- php - 将数组与祖先元素混合
- c++ - 理解 C 链接器错误:多重定义
- angular - 如何在 ionic 4 和 angular 7 中正确导入管道?
- elasticsearch - 过期滚动上下文的 Elasticsearch 回复
- tensorflow - tx2 protobuf 上的张量流
- azure-devops - 在 Azure DevOps 构建定义中下载最新版本的构建工件时未找到最新构建
- r - R:从基于连续变量的分类变量创建一个新的分类变量
- git - 如何将 TFS 拉取请求中的 Jenkins 作业与合并的分支进行排队