Hide the filters in Shiny DT datatable

不羁的心 提交于 2019-12-24 16:25:06

问题


In my shiny app I'm creating a datatable using the DT package. I have column filters enabled, however, I want to hide the row of filter boxes. I have separate shiny widgets outside of the datatable which will act as the filters and pass them to the datatable through the searchCols option. Disabling column filters would hide the row of filter boxes but then the searchCols option doesn't work.

When I run the app and inspect the elements, I see that the row I want to delete is called < tr role="row">...< /tr>. If I right click it and click "Delete element", the row disappears and the datatable looks like I want it to, with the outside filters working as intended. I can also accomplish that by adding "display:none" to the element.style css. My question is how do I tell the app to delete this row when the datatable is rendered?

I'm not sure what kind of reproducible code I could provide, but here are some screenshots to make it clearer what I want to do.

I want to remove all the filter boxes and the row they are in so that the data is right below the column headers, as if filters were not enabled.

If I inspect the app and delete the highlighted element or add "display:none", the row gets hidden. How can I make this happen automatically when the datatable is rendered?


回答1:


I don't know if this will work with your widgets, but you can try this to set the display property in the styling sheet, using an id selector and a child selector:

library(shiny)
library(DT)

ui <- fluidPage(
  tags$style("#mydatatable thead > tr:nth-child(2) {display:none;}"),
  mainPanel(
    dataTableOutput("mydatatable")
  )
)

server <- function(input, output) {

  output$mydatatable <- DT::renderDataTable(
    datatable(iris, filter = 'top', options = list(
              pageLength = 5, autoWidth = TRUE)
    )
  )

}

shinyApp(ui = ui, server = server)


来源:https://stackoverflow.com/questions/51119372/hide-the-filters-in-shiny-dt-datatable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!