8

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

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

Mal_a
  • 3,670
  • 1
  • 27
  • 60
  • Which version of `DT` you use? For [example](https://yihui.shinyapps.io/DT-info/) you need `DT` (>= 0.1.26) – Batanichek Feb 03 '16 at 13:11
  • DT 0.1. There is newer version available? Just checked it out and it seems only 0.1 is available – Mal_a Feb 03 '16 at 13:14
  • You can install github version `devtools::install_github('rstudio/DT')` ( need installed `library(devtools)`) – Batanichek Feb 03 '16 at 13:16
  • Just got an error while installing it: > `devtools::install_github('rstudio/DT') Downloading GitHub repo rstudio/DT@master from URL https://api.github.com/repos/rstudio/DT/zipball/master Installing DT "C:/Program Files/R/R-32~1.3/bin/x64/R" --no-site-file --no-environ --no-save --no-restore CMD INSTALL \ "C:/Users/asadm/AppData/Local/Temp/Rtmpkf86pZ/devtools870457c693c/rstudio-DT-2c636f6" \ --library="C:/Users/am/Documents/R/win-library/3.2" --install-tests Der Befehl "C:\Program" ist entweder falsch geschrieben oder konnte nicht gefunden werden. Error: Command failed (1)` – Mal_a Feb 03 '16 at 13:20
  • There's a bug in your example. line 17 should be `filtered_data <- data[input$tbl_rows_all,]` – CPhil Feb 05 '16 at 19:51
  • Based on the GoogleTranslate rendition of your error message, I think R is getting confused by the space in "C:\Program Files\...". I would suggest trying to manually specify a different library location, to a path with no spaces. – CPhil Feb 05 '16 at 19:53
  • Hey CPhil, I am going to check it out on Monday at work..However i am not sure if i can do it as i do not have admin rights ... Gonna update You anyways. You think the general problem of not retrieving all rows is the DT version? Thanks for Your time and tipps!Cheers PS. The bug: I typed it wrong but in my orginal code is correct, sorry for it – Mal_a Feb 06 '16 at 09:29

1 Answers1

6

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

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

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

CPhil
  • 917
  • 5
  • 11
  • I am using datable DT version 0.1 in shiny dashboard and im sure it is not working for me :( just cannot understand why – Mal_a Feb 05 '16 at 19:20
  • @Malvina_a Did `devtools::install_github('rstudio/DT')` work? If so, I have no idea what the problem might be. If it did not work, then I suspect that your problem will go away when you get that to work - maybe get IT to give you temporary admin rights? – CPhil Feb 08 '16 at 18:25
  • I have just tried the way around, i downloaded the development version mentioned in the post (http://stackoverflow.com/questions/34140704/r-shiny-where-can-we-find-the-tar-gz-file-of-the-master-version-of-dt-packa), then i used command `install.packages("C:/Users/XX/Downloads/DT-master.tar.gz",lib="C:/Users/XX/Documents/R/win-library/3.2")`. Howver still i got error: `Warning in install.packages : package ‘C:/Users/XX/Downloads/DT-master.tar.gz’ is not available (for R version 3.2.3)`... – Mal_a Feb 09 '16 at 07:23