Empty “row-fluid” div at top and bottom of dataTab

2019-02-26 05:16发布

I have a shiny example using renderDataTable() to create an output.

I have removed all possible options (paging, filtering, searching, etc). However, there is now a blank row at the top and bottom of my table output, where the filtering and searching used to be.

How can I remove these two divs from inside the datatable wrapper, only when I have removed the filtering and searching options?

ui.R:

library(shiny)
shinyUI(pageWithSidebar(
  headerPanel("dataTable Example"),
  sidebarPanel(
    "This is a sidebar"
  ),
  mainPanel(
    p("Check out the gaps below."),
    wellPanel(
               dataTableOutput('example1')),
    p("No gaps here because of searching and paging."),
    wellPanel(
               dataTableOutput('example2')
        )
    )
  )
)

server.R:

library(shiny)
    shinyServer(function(input, output) {
      x<-c(1,2,3,4,5)
      y<-c('a','b','c','d','e')
      test<-data.frame(x,y)
      output$example1<-renderDataTable({test},options = list(iDisplayLength = 5,bSearchable = FALSE
                                                            ,bFilter=FALSE,bPaginate=FALSE,bAutoWidth=TRUE
                                                            ,bInfo=0,bSort=0))  
      output$example2<-renderDataTable({test})  
    })

1条回答
女痞
2楼-- · 2019-02-26 05:23

You can use the sDom option see http://legacy.datatables.net/usage/options#sDom for more details:

library(shiny)
runApp(list( ui =pageWithSidebar(
  headerPanel("dataTable Example"),
  sidebarPanel(
    "This is a sidebar"
  ),
  mainPanel(
    p("Check out the gaps below."),
    wellPanel(
      dataTableOutput('example1')),
    p("No gaps here because of searching and paging."),
    wellPanel(
      dataTableOutput('example2')
    )
  )
)
, server = function(input, output) {
  x<-c(1,2,3,4,5)
  y<-c('a','b','c','d','e')
  test<-data.frame(x,y)
  output$example1<-renderDataTable({test},options = list(iDisplayLength = 5,bSearchable = FALSE
                                                         ,bFilter=FALSE,bPaginate=FALSE,bAutoWidth=TRUE
                                                         ,bInfo=0,bSort=0
                                                         , "sDom" = "rt"
                                                         ))  
  output$example2<-renderDataTable({test})  
}
)
)

enter image description here

查看更多
登录 后发表回答