简体   繁体   English

r闪亮的下载过滤数据表(DT)

[英]r shiny download filtrered datatables (DT)

i'm trying to do a shiny app to download a filtred Datatable : 我正在尝试做一个shiny应用程序来下载过滤的Datatable

  • filtered with the searsh searsh过滤
  • filtred by deleting line with the delete button 通过使用delete button删除行来过滤

(the download part is working as intended) (下载部分正在按预期工作)

the problem : when i first filter with the searsh area from Datatable if i delete a line with the button it reset the first filter 问题:当我第一次使用Datatable中的searsh区域进行过滤时,如果我使用按钮删除了一行,则会重置第一个过滤器

my reproductible exemple : edit working solution 我的可复制示例: 编辑工作解决方案

library(shinydashboard)
library(DT)
library(shiny)

ui <- dashboardPage(
  dashboardHeader(title = "Info boxes"),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(DT::dataTableOutput('data')),
    fluidRow(p(class = 'text-center', downloadButton('x3', 'Download Filtered Data')))
  )
)

server <- function(input, output) {
   df <- reactiveValues(data = data.frame(
      Value1 = 1:10,
      Value2 = c("A", "B", "C", "D", "E"),
      stringsAsFactors = FALSE,
      row.names = 1:10
   ))

   output$data <- DT::renderDataTable(
   df$data, server =  TRUE, filter = 'top', escape = FALSE, selection = 'none')

   # download the filtered data
    output$x3 = downloadHandler('emergence filtré.csv', content = function(file) {
        s = input$data_rows_all
        write.table(df$data[s,], file  ,sep=";",row.names = F)
     })    
}
shinyApp(ui = ui, server = server)

Thank you 谢谢

I think this is because the search filter is done on the client's side (within the web browser) and it does not really change the underlying data frame. 我认为这是因为搜索过滤器是在客户端(在Web浏览器中)完成的,并且实际上并没有改变底层的数据框架。 A possible alternative is to add a filter to the table and use that as search function, and also set server side processing. 一种可能的替代方法是将过滤器添加到表中,并将其用作搜索功能,并设置服务器端处理。 This won't do global searching in one box though. 但是,这不会在一个框中进行全局搜索。

output$data <- DT::renderDataTable(
  df$data, server = TRUE, filter = 'top', escape = FALSE, selection = 'none'
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM