Using filtered datatables in shiny Using filtered datatables in shiny r r

Using filtered datatables in shiny


Just building up on @JasonAizkalns's example, you can hide some of the built-in column filters using jQuery. for example here the first two are hidden:

library(shiny)library(DT)shinyApp(  ui = fluidPage(dataTableOutput('tbl'),                 plotOutput('plot1')),  server = function(input, output) {        output$tbl = renderDataTable({      datatable(iris, filter="top",options = list(lengthChange = FALSE),callback=JS("           //hide column filters for the first two columns          $.each([0, 1], function(i, v) {                $('input.form-control').eq(v).hide()              });"))    })    output$plot1 = renderPlot({      filtered_data <- input$tbl_rows_all      hist(iris[filtered_data, "Sepal.Length"])    })  })


The example suggested by @NicE is very helpful. I am including a minimal example below:

library(shiny)library(DT)shinyApp(  ui = fluidPage(dataTableOutput('tbl'),                 plotOutput('plot1')),  server = function(input, output) {        output$tbl = renderDataTable({      datatable(iris, options = list(lengthChange = FALSE))    })    output$plot1 = renderPlot({      filtered_data <- input$tbl_rows_all      hist(iris[filtered_data, "Sepal.Length"])    })  })

This will generate a histogram of Sepal.Length from the iris data set for the filtered data in the DT::datatable.

Note: This assumes the following versions of DT and shiny:

DT_0.0.39 shiny_0.11.1.9005