Shiny DT(数据表)中的自然排序不起作用

Natural sorting in Shiny DT (datatables) doesn't work

尊敬的Shiny和DT高手们! 我正在尝试在我的闪亮应用程序中使用自然排序插件,但它似乎不起作用。我认为它在 DT 包之前与以前版本的 Shiny or/and 一起使用。有谁能够帮助我?请参阅下面的示例(我正在尝试对最后一列进行排序):

server.R

library(shiny)
require(DT)
shinyServer(function(input, output) {
    output$example <- DT::renderDataTable({
        table = cbind(LETTERS[1:5],matrix(1:20,nrow=5),c(1,2,3,10,"a"))
        table = rbind(c("filtered",round(rnorm(5),3)),table)
        DT::datatable(table,
                      rownames = FALSE,
                      extensions = list(FixedColumns = list(leftColumns = 1)),
                      options = list(
                          columnDefs = list(list(type = "natural", targets = "_all"))))
    })
})

ui.R

library(shiny)
require(DT)
shinyUI(
    fluidPage(
        tags$head(
            tags$script(src = "http://cdn.datatables.net/1.10.6/js/jquery.dataTables.min.js", type = "text/javascript"),
            tags$script(src = "http://cdn.datatables.net/plug-ins/1.10.7/sorting/natural.js", type = "text/javascript")
        ),
        DT::dataTableOutput('example')
    )
)

DT(>=0.1.16)的current development version中,您可以使用datatable(..., plugins = 'natural')启用此插件,例如

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    DT::dataTableOutput('example')
  ),
  server = function(input, output) {
    output$example <- DT::renderDataTable({
      table = cbind(LETTERS[1:5],matrix(1:20,nrow=5),c(1,2,3,10,"a"))
      table = rbind(c("filtered",round(rnorm(5),3)),table)
      table
    }, server = FALSE, plugins = 'natural', options = list(
      columnDefs = list(list(type = "natural", targets = "_all"))
    ))
  }
)

有关详细信息,请参阅 the documentation