【问题标题】:filter = 'top' does not execute in Shiny appfilter = 'top' 不在 Shiny 应用程序中执行
【发布时间】:2016-02-05 09:59:38
【问题描述】:

我刚刚使用 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 = ', ')
    }
  })

  }
)

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    像这样将 filter='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')
    

    【讨论】:

    • 感谢您的建议。
    猜你喜欢
    • 2013-12-27
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多