使用DT包隐藏响应数据表中的某些列 [英] Hide certain columns in a responsive data table using DT package

查看:59
本文介绍了使用DT包隐藏响应数据表中的某些列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 DT 包为闪亮的应用程序创建响应数据表。我想提前隐藏某些列。例如:

I am trying to create a responsive data table for my shiny application using DT package. I want to hide certain columns in advance. For example:

library("shiny")
library("DT")
shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(
      iris,extensions="Responsive"
    )
  }
)

此输出给了我5列。当我缩小页面时,它仅隐藏列。但是,我想提前隐藏最后三列,而每次只想看到前两列。有没有办法做到?

This output gives me 5 columns. It only hides columns when I narrow the page. But, I want to hide last 3 columns in advance and I just want to see first two columns every time. Is there a way to do that?

更新:

示例输出

推荐答案

您可以使用DT选项或扩展名隐藏表中的列。

You can hide columns in your table using DT options or extensions.

如果您希望预先隐藏它们,但需要一个按钮使其再次显示,则 ColVis 扩展名应该很适合您:链接

If you want them to be hidden in advance but have a button to make them visible again, the ColVis extension should work well for you: link

如果您只想隐藏这些内容,请添加以下选项(不记得我现在在哪里看到过它的文档。)

If you just want thme stay hidden, add the following option (can't remember where I've seen its documentation right now..)

options=list(columnDefs = list(list(visible=FALSE, targets=columns2hide)))

这篇关于使用DT包隐藏响应数据表中的某些列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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