Datatable (DT)闪亮R -选择所有找到的行

时间:2021-02-07 14:26:07

I have a question about datatable (DT) which i am using in Shiny. I got quite big data (>5000000 rows), and i display it in shiny app using datatable (DT) with filters. Depending on the user preferences for filtering, lets assume it gives us 550 rows (but it can give us more or less than that). Because of pagination I am not able to see all 550 rows (assuming pageLength is 100) or whats even worse, i am not able to display all filtered rows further in a plot, as function input$tabelle_rows_all uses the rows on the current page (i must first change the entries number). Is there any way to get all found rows after filtering datatable (not depended on pageLength)?

我有一个关于datatable (DT)的问题,我正在使用它。我得到了相当大的数据(>5000000行),我使用带过滤器的datatable (DT)在闪亮的应用程序中显示它。根据用户对过滤的偏好,假设它给了我们550行(但它可以给我们更多或更少的行)。由于分页,我不能看到所有550行(假设pageLength是100)或者更糟糕的是,我不能在一个图中显示所有经过过滤的行,因为函数输入$tabelle_rows_all使用当前页上的行(我必须首先更改条目号)。是否有办法在过滤了数据表(不依赖于pageLength)之后获取所有找到的行?

Example:

例子:

library(shiny)
library(DT)
library(ggplot2)

x <- as.numeric(1:1000000)
y <- as.numeric(1:1000000)
data <- data.frame(x,y)

shinyApp(
  ui = fluidPage(dataTableOutput('tableId'),
                 plotOutput('plot1')),
  server = function(input, output) {    
    output$tableId = renderDataTable({
      datatable(data, options = list(pageLength = 100, lengthMenu=c(100,200,300,400,500,600)))
    })
    output$plot1 = renderPlot({
      filtered_data <- data[input$tableId_rows_all, ]
      ggplot(data=filtered_data, aes(x=x,y=y)) + geom_line()
    })
  }
)

Thanks for any Info

谢谢你的任何信息

1 个解决方案

#1


2  

Are you sure it's not working already? As of version 0.0.65, you should have the following:

你确定它已经不起作用了吗?在0.65版本中,您应该具有以下内容:

input$tableId_rows_current: the indices of rows on the current page
input$tableId_rows_all: the indices of rows on all pages (after the table is filtered by the search strings)
From the DT documentation

输入$tableId_rows_current:当前页上的行索引输入$tableId_rows_all: DT文档中所有页上的行索引(在搜索字符串过滤表之后)

I'm using tableId_rows_all in a dashboard for exactly this and it is working.

我在一个仪表板中使用tableId_rows_all来完成这个工作。

#1


2  

Are you sure it's not working already? As of version 0.0.65, you should have the following:

你确定它已经不起作用了吗?在0.65版本中,您应该具有以下内容:

input$tableId_rows_current: the indices of rows on the current page
input$tableId_rows_all: the indices of rows on all pages (after the table is filtered by the search strings)
From the DT documentation

输入$tableId_rows_current:当前页上的行索引输入$tableId_rows_all: DT文档中所有页上的行索引(在搜索字符串过滤表之后)

I'm using tableId_rows_all in a dashboard for exactly this and it is working.

我在一个仪表板中使用tableId_rows_all来完成这个工作。