The following is a direct replication of the datatable demo provided on the rstudio shiny website. It is quite easy to filter the dataset (e.g. Ideal on the diamond, or setosa on the iris), however is there a way to filter multiple conditions such as 'Ideal' and 'Fair' in the diamond dataset? I have tried the basic 'AND' and '&' syntax, spaces, nothing seems to work. This seems like it should be possible but is this even possible or does it require some roundabout approach?
require(shiny)
runApp(
list(ui = fluidPage(
title = 'Examples of DataTables',
sidebarLayout(
sidebarPanel(
conditionalPanel(
'input.dataset === "diamonds"',
checkboxGroupInput('show_vars', 'Columns in diamonds to show:',
names(diamonds), selected = names(diamonds))
)
),
mainPanel(
tabsetPanel(
id = 'dataset',
tabPanel('diamonds', dataTableOutput('mytable1'))
)
)
)
),
server = shinyServer(function(input, output) {
# a large table, reative to input$show_vars
output$mytable1 <- renderDataTable({
library(ggplot2)
diamonds[, input$show_vars, drop = FALSE]
})
})
)
)
After some further search, I suspect I should be able to use the jquery column filter plugin. To simplify this question, here is a more stripped down version of the above code:
library(shiny)
runApp(
list(ui = basicPage(
h1('Diamonds DataTable with TableTools'),
# added column filter plugin
singleton(tags$head(tags$script(src='https://code.google.com/p/jquery-datatables-column-filter/source/browse/trunk/media/js/jquery.dataTables.columnFilter.js',
type='text/javascript'))),
dataTableOutput("mytable")
)
,server = function(input, output) {
output$mytable = renderDataTable({
diamonds[,1:6]
}, options = list(
pageLength = 10,
columnDefs = I('[{"targets": [0,1],
"searchable": true}]')
)
)
}
))
However, I cannot seem to get the columnFilter plugin to work. The columnDefs statement (commented out) works fine but when I try to do the columnFilter statement, I get only get the table header and filter search boxes. I suspect some syntax must be off to get this to work. As an example of the functionality, please see this website. Please note, this is also using the most recent version of shiny from the rstudio github