简体   繁体   English

向R中的数据表DT添加条件行边界

[英]Adding conditional row borders to datatables DT in R

I'm trying to add row borders in the middle of a datatable to separate the information more clearly, but haven't had any luck so far. 我正在尝试在数据表的中间添加行边框,以更清楚地分隔信息,但是到目前为止还没有任何运气。 Lets take mtcars datatable as example and an auxiliar vector which will define the rows where I want the borders, such as aux=c(3,6,8) 让我们以mtcars为例,并使用一个辅助矢量来定义我想要边框的行,例如aux=c(3,6,8)

How can I define the row borders with this aux vector? 如何使用此aux向量定义行边界? Is it possible to do with functions like formatStyle? 是否可以使用诸如formatStyle之类的功能? The final table should be something like this: final table 决赛桌应该是这样的: 决赛桌

Thanks! 谢谢!

library(DT)

dat <- mtcars
aux <- c(3,6,8)
dat$hiddenColumn <- 0
dat$hiddenColumn[aux] <- 1

datatable(dat, 
          options = list(
            columnDefs = list(
              list(visible = FALSE, targets = ncol(dat))
            )
          )) %>%
  formatStyle(0:ncol(dat), valueColumns = "hiddenColumn",
              `border-bottom` = styleEqual(1, "solid 3px"))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM