Datatable (DT) Shiny R - 来自逗号分隔字符串的自定义 SearchPane

Datatable (DT) Shiny R - Custom SearchPane from comma-separated string

我正在尝试创建一个 DT SearchPanes 自定义过滤器,它将以逗号分隔的字符串列视为单独的条目。我知道如何在 Datatables 中完成这项工作(参见 here), but I'm struggling with using the proper syntax to get it to work in DT ( post 很有帮助,但并没有完全让我到达那里)。

当我 运行 应用程序时,我得到一个空的 SearchPane,上面写着“table 中没有可用数据”。

这是我的代码。我对 DT(和 Javascript)还很陌生,所以我想知道我是否遗漏了一些明显的东西?任何帮助将不胜感激!

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)

我没试过,不过这里是link中给出的代码的翻译。

datatable(
  cover,
  extensions = c('Select', 'SearchPanes'),
  selection = 'none',
  options = list(
    dom = "Pfrtip", 
    searchPanes = list(
      threshold = 1,
      columns = list(7)
    ),
    columnDefs = list(
      list(
        targets = 7,
        render = JS(
          "function (data, type, row) {",
          "  if (type === 'sp') {",
          "    return data.split(', ');",
          "  }",
          "  return data;",
          "}"
        ),
        searchPanes = list(orthogonal = "sp")
     )
   )
  )
)