I'm trying to create a DT SearchPanes custom filter that treats a column that is a comma-separated string as separate entries. I know how to make this work in Datatables (see here), but I'm struggling with using the proper syntax to get it to work in DT (this post was helpful, but isn't quite getting me there).
When I run the app I get an empty SearchPane that says "no data available in table."
Here's my code. I'm pretty new to DT (and Javascript), so I'm wondering if I'm missing something obvious? Any help would be greatly appreciated!
server <- function(input, output) {
cover <- read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vQaZCDpH85S4jj0kgHhTDdJTYrjMCyo1CZOHwAlkEl3YOBgFwVwdHZ8xmAa-xW7UHLo8_Snkrjj450B/pub?gid=0&single=true&output=csv")
cover$Cover.crop <- as.factor(cover$Cover.crop)
cover$Type <- as.factor(cover$Type)
cover$Growing.Season <- as.factor(cover$Growing.Season)
colnames(cover)<- c("Cover Crop","Growing Season","Crop Category","Min. Water (in)", "Min. Soil pH","Max. Soil pH","Environmental Benefits","USDA Hardiness Zones","Max. Height (in)","Bloom Time","Perennial?","Salinity Tolerance","Poor Drainage Tolerance", "Use Before Legume?","Forage Quality")
output$covertable <- DT::renderDataTable(server=FALSE, {
DT::datatable(
cover,
options = list(
dom = 'Pfrtip',
columnDefs = list(
list(
searchPanes = list(
show = TRUE,
options = list(
orthogonal = 'sp',
value = JS(
"function(rowData, rowIdx) {
if (type === 'sp') {
return data.split(', ')
}
return data;}"
))),
targets = 7
),
list(
searchPanes = list(show = FALSE), targets = 2:15
)
)
),
extensions = c('Select', 'SearchPanes'),
selection = 'none'
)
})}
ui <- fluidPage(
hr(),
DT::dataTableOutput('covertable')
)
shinyApp(ui = ui, server = server)