R-下载过滤的数据表 [英] R - Download Filtered Datatable

查看:76
本文介绍了R-下载过滤的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用内置搜索将其过滤后下载一个数据表。或能够使用与数据表中相同的搜索来过滤数据帧并访问数据表中的搜索。

I would like to be able to download a datatable after it is filtered using it's built in search. Either that or be able to filter a dataframe using the same kind of search used in a datatable and access the search on a datatable.

推荐答案

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

If you use client side processing, you can accomplish this with the input object input[["tablename_rows_all"]]. (append _rows_all to the name of the datatable output slot)

_rows_all 对象将返回数据框的行索引。您可以在 downloadHandler 中使用该子集来启动下载时的数据帧。

The _rows_all object will return the row indices of your data frame. You can use that within your downloadHandler to subset the data frame when the download is initiated.

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)
          }
        )
    })
)

这篇关于R-下载过滤的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆