Shiny DT(数据表)中的自然分类不起作用

时间:2015-07-09 13:21:33

标签: r datatables shiny dt

亲爱的Shiny和DT大师! 我正试图在我的闪亮应用程序中使用自然分类插件,但它似乎不起作用。我认为它与之前版本的Shiny或/和DT包之前一起使用。有谁能够帮我?请参阅下面的示例(我正在尝试对最后一列进行排序):

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')
    )
)

1 个答案:

答案 0 :(得分:1)

DT current development version(&gt; = 0.1.16)中,您可以使用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