隐藏Shiny DT数据表中的过滤器 [英] Hide the filters in Shiny DT datatable

查看:56
本文介绍了隐藏Shiny DT数据表中的过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在闪亮的应用程序中,我正在使用DT包创建数据表。我启用了列过滤器,但是,我想隐藏过滤器框的行。我在数据表之外有单独的闪亮小部件,这些小部件将充当过滤器,并通过searchCols选项将其传递给数据表。禁用列过滤器会隐藏过滤器框的行,但是searchCols选项不起作用。

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.

当我运行应用程序并检查元素时,我看到该行我要删除的称为< tr role = row> ...< / tr>。如果右键单击它,然后单击删除元素,则该行消失,数据表看起来像我想要的那样,外部过滤器按预期工作。我也可以通过在element.style css中添加 display:none来实现。我的问题是如何在呈现数据表时告诉应用程序删除该行?

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.

如果我检查了该应用并删除了突出显示的元素或添加了 display:none,行被隐藏。呈现数据表时,如何自动进行此操作?

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?

推荐答案

我不知道这是否可行与您的小部件一起使用,但是您可以尝试使用 id 选择器并在样式表中设置 display 属性子选择器:

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)

这篇关于隐藏Shiny DT数据表中的过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆