从 R shiny 中的 DataTable 按钮扩展下载文件名的动态命名

Dynamic naming of download filename from DataTable buttons extension in R shiny

我有:


library(shiny)
library(DT)

ui <- fluidPage(
    h2("Explorer"),

    tabPanel(h3("Inspector"),
             p("Overview of data for a particular sample."),
             selectInput(inputId = "sample",
                         label = h3("Select sample"),
                         selectize = TRUE,
                         choices = names(vcf_tibbles)),
             dataTableOutput("sample_inspector")
            )
    )

server <- function(input, output) {
  output$sample_inspector <- DT::renderDataTable(

      sample_overview(sample_id = input$sample, vcf_tibbles = vcf_tibbles),
      rownames = FALSE,
      extensions = 'Buttons',
      options = list(paging = FALSE,
             dom = 'Bfrtip',
             buttons = list( list(extend = 'csv',   filename =  paste("snp", input$sample, sep = "-")),
                     list(extend = 'excel', filename =  paste("snp", input$sample, sep = "-"))))
      )
}

一切正常,因为我 select 一个示例并且 table 相应更新。如果我单击 CSV 或 Excel,则会下载相应的 dta。但是,文件名总是错误的

似乎正在更新数据 table 的内容,但是 input$sample 没有考虑使用按钮。

有没有办法让按钮中的文件名参数也具有反应性?

我试图让这个名字成为函数调用的结果,但也无法让它发挥作用。

谢谢!

这是这样工作的:

server <- function(input, output) {
  output$sample_inspector <- DT::renderDataTable(
    iris,
    rownames = FALSE,
    extensions = 'Buttons',
    options = exprToFunction(
      list(paging = FALSE,
           dom = 'Bfrtip',
           buttons = list( 
             list(extend = 'csv',   filename =  paste("snp", input$sample, sep = "-")),
             list(extend = 'excel', filename =  paste("snp", input$sample, sep = "-"))))
    )
  )
}