我正在使用 R 的可反应包来创建按特定变量分组的数据表。这将显示一个折叠的表格,可以展开该表格以显示子行。折叠的行标题旁边有一组括号,指示下面嵌套了多少个子行。是否可以抑制这组括号使其不显示?这会让我的用户感到困惑。
这是一个例子。如果我运行下面的代码块,它会生成一个按物种分组的表,每个物种旁边都有一组括号,例如“Setosa (50)”。如何从该字符串中删除“(50)”,使其只显示“Setosa”?感谢您的帮助!
library(reactable)
reactable(iris, groupBy = "Species", columns = list(
Sepal.Length = colDef(aggregate = "count"),
Sepal.Width = colDef(aggregate = "mean"),
Petal.Length = colDef(aggregate = "sum"),
Petal.Width = colDef(aggregate = "max")
))
这个问题很老了,但是有一种更干净的方法来处理这个问题,而不是直接调整 CSS。您可以在 colDef 方法的
grouped
属性中编写一个 javascript 函数,该函数定义分组时单元格文本中呈现的内容。这是文档中的一个简单示例,可实现所需的结果:
colDef(
# Render grouped cells without the row count
grouped = JS("function(cellInfo) {
return cellInfo.value
}")
您可以在他们的文档
中看到它的使用情况可以通过一些CSS魔法来实现:
首先,在您的可响应调用中添加一些自定义类:
library(reactable)
reactable(
iris,
groupBy = "Species",
class = "noParenthesis"
)
然后将以下样式添加到您的 css 文件中:
.noParenthesis .rt-expandable > div {
height: 21px;
display: -webkit-inline-box;
}
.noParenthesis .rt-expandable > div > span {
display: table-caption;
color: transparent;
}
.noParenthesis .rt-expandable > div > span:first-line {
color: #333333;
}
看起来答案还没有 - 根据这里的问题 https://github.com/glin/reactable/issues/94 来自维护者
glin
:
今天这是不可能的,即使使用自定义 JS,但之前已经请求过(#33)。我会将其放入下一个版本的列表中。用法可能看起来像这样: