代码之家  ›  专栏  ›  技术社区  ›  SNT

R闪亮的数据表分页并将所有行显示为选项

  •  0
  • SNT  · 技术社区  · 7 年前

    library(shiny)
    library(DT)
    library(shinyWidgets)
    library(shiny)
    
    
    shinyApp(
    
      ui = navbarPage(
        title = 'DataTable',
        tabPanel('Display length',     DT::dataTableOutput('ex2'))
      ),
    
      server = function(input, output, session) {
    
        output$ex2 <- DT::renderDataTable(
          DT::datatable(
            iris, options = list(
              lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
              pageLength = 15
            )
          )
        )
    
        }
        )
    
    0 回复  |  直到 7 年前
        1
  •  4
  •   dww Jarretinha    7 年前

    这个呢,使用按钮扩展。我们定义了一个调用javascript函数的自定义按钮 page.len(-1) ,其中 -1 表示所有行:

    shinyApp(
    
      ui = navbarPage(
        title = 'DataTable',
        tabPanel('Display length',     DT::dataTableOutput('ex2'))
      ),
    
      server = function(input, output, session) {
    
        output$ex2 <- DT::renderDataTable(
          DT::datatable(
            iris, 
            extensions = 'Buttons',
            options = list(
              dom = 'Bfrtip',
              lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
              pageLength = 15,
              buttons = list(
                list(
                  extend = "collection",
                  text = 'Show All',
                  action = DT::JS("function ( e, dt, node, config ) {
                                        dt.page.len(-1);
                                        dt.ajax.reload();
                                    }")
                )
              )
            )
          )
        )
    
      }
    )
    
        2
  •  0
  •   SNT    7 年前
    library(dplyr)
    library(shiny)
    library(DT)
    
    shinyApp(
    
      ui = navbarPage(
        title = 'DataTable',
        tabPanel('Display length',     DT::dataTableOutput('ex2'))
      ),
    
      server = function(input, output, session) {
    
        output$ex2 <- DT::renderDataTable(
          DT::datatable(
            iris, 
            extensions = 'Buttons',
            options = list(
              dom = 'tpB',
              lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
              pageLength = 15,
              buttons = list(
                list(
                  extend = "collection",
                  text = 'Show All',
                  action = DT::JS("function ( e, dt, node, config ) {
                                  dt.page.len(-1);
                                  dt.ajax.reload();}")
                ),list(
                  extend = "collection",
                  text = 'Show Less',
                  action = DT::JS("function ( e, dt, node, config ) {
                                  dt.page.len(10);
                                  dt.ajax.reload();}")
    
                  )
                  )
                  )
                )
              )
    
      }
          )
    
    推荐文章