filter = 'top' 不在闪亮的应用程序中执行

filter = 'top' does not execute in Shiny app

我刚刚使用 DT 创建了以下 Shiny 应用程序。我的问题是 filter='top' 实际上似乎没有执行。合并 checkboxGroupInput 和来自 DT 的过滤器是否有问题?我希望能够添加尽可能多的过滤选项。

ui.R

library(shiny)


shinyUI(pageWithSidebar(
  headerPanel('Database'),
  sidebarPanel(

    p('Welcome to the Database.'),

    p('(1) Use the dropdown menus to select a category, type, or  manufacturer.'),
    p('(2) Use the checkboxes below to add or remove information from the table.'),

    checkboxGroupInput('show_vars', 'Information:', names(Foods),
                       selected = names(Foods)),

  ),
  mainPanel(

    fluidRow(h1('A Server-side Table')),

    fluidRow(
      column(9, DT::dataTableOutput('x3')),
      column(3, verbatimTextOutput('x4'))
    )
  )
)
)

server.R

library(shiny)
library(DT)

shinyServer(function(input, output, session) {

  # server-side processing

  output$x3 = DT::renderDataTable(Foods[, input$show_vars, drop = TRUE], server = TRUE, 
                                  options = list(pageLength = 5, autoWidth = TRUE,
                                                 columnDefs = list(list(width = '200px', targets = "_all"))
                                                 , filter = 'top'))

  # print the selected indices
  output$x4 = renderPrint({
    s = input$x3_rows_selected
    if (length(s)) {
      cat('These rows were selected:\n\n')
      cat(s, sep = ', ')
    }
  })

  }
)

将过滤器='top' 移至 renderDataTable,如下所示:

  output$x3 = DT::renderDataTable(iris[, input$show_vars, drop = TRUE], server = TRUE, 
                                  options = list(pageLength = 5, autoWidth = TRUE,
                                                 columnDefs = list(list(width = '200px', targets = "_all"))
                                                 ),filter='top')