【问题标题】:R - Download Filtered DatatableR - 下载过滤后的数据表
【发布时间】:2017-05-26 14:37:04
【问题描述】:

我希望能够在使用内置搜索对其进行过滤后下载数据表。或者能够使用数据表中使用的相同类型的搜索来过滤数据框并访问数据表上的搜索。

【问题讨论】:

  • 到目前为止你尝试了什么?
  • @PorkChop 我已经尝试寻找一种方法来访问数据表的内部结构,并且我已经尝试编写自己的搜索,但它的效果不如数据表搜索。文档没有显示向服务器提供过滤的真正方法。
  • 贴出你尝试的代码,让我们看看
  • @PorkChop 我的大部分尝试都是阅读文档。

标签: r shiny dt


【解决方案1】:

如果您使用客户端处理,您可以使用输入对象input[["tablename_rows_all"]] 完成此操作。 (将_rows_all附加到数据表输出槽的名称)

_rows_all 对象将返回数据框的行索引。您可以在您的downloadHandler 中使用它来在下载开始时对数据框进行子集化。

library(shiny)
library(DT)

shinyApp(
  ui = 
    shinyUI(
      fluidPage(
        DT::dataTableOutput("dt"),

        p("Notice that the 'rows_all' attribute grabs the row indices of the data."),
        verbatimTextOutput("filtered_row"),


        downloadButton(outputId = "download_filtered",
                       label = "Download Filtered Data")
      )
    ),

  server = 
    shinyServer(function(input, output, session){
      output$dt <- 
        DT::renderDataTable(
          datatable(mtcars,
                    filter = "top"),
          server = FALSE
        )

      output$filtered_row <- 
        renderPrint({
          input[["dt_rows_all"]]
        })


      output$download_filtered <- 
        downloadHandler(
          filename = "Filtered Data.csv",
          content = function(file){
            write.csv(mtcars[input[["dt_rows_all"]], ],
                      file)
          }
        )
    })
)

【讨论】:

  • 我正在尝试使用“d3tablefilter”下载过滤后的数据表(与具有过滤限制的数据表不同,它允许过滤多个字符串)。但是,复制您的代码以进行下载是行不通的。你能帮忙吗?? github.com/ThomasSiegmund/D3TableFilter
猜你喜欢
  • 2016-08-18
  • 2021-11-20
  • 2019-11-01
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多