0

我正在使用 rMarkdown,编织到 html,并尝试在可反应中做一些简单的事情 - 使用 JS 来抑制括号中的行总数。我实际上是从他们自己的指南中复制的,但它不起作用:

可反应的分组单元格渲染

data <- MASS::Cars93[10:22, c("Manufacturer", "Model", "Type", "Price", "MPG.city")]

reactable(
  data,
  groupBy = c("Manufacturer", "Type"),
  columns = list(
    Manufacturer = colDef(
      # Render grouped cells without the row count
      grouped = JS("function(cellInfo) {
        return cellInfo.value
      }")
    )
  )
)

我收到以下错误:

Error in colDef(grouped = JS("function(cellInfo) {\n return cellInfo.value\n }")) : 
unused argument (grouped = JS("function(cellInfo) {\n return cellInfo.value\n }"))

任何帮助将非常感激。

4

1 回答 1

0

grouped参数在包的 CRAN 版本上不可用(还)。您可以从 github 安装开发版本,然后示例运行。

#install the package from github
#devtools::install_github("glin/reactable")
library(reactable)
data <- MASS::Cars93[10:22, c("Manufacturer", "Model", "Type", "Price", "MPG.city")]

reactable(
  data,
  groupBy = c("Manufacturer", "Type"),
  columns = list(
    Manufacturer = colDef(
      # Render grouped cells without the row count
      grouped = JS("function(cellInfo) {
        return cellInfo.value
      }")
    ),
    Type = colDef(
      # Render grouped cells with the row count, only if there are multiple sub rows
      grouped = JS("function(cellInfo) {
        if (cellInfo.subRows.length > 1) {
          return cellInfo.value + ' (' + cellInfo.subRows.length + ')'
        }
        return cellInfo.value
      }")
    )
  )
)

在此处输入图像描述

于 2021-09-30T13:14:52.753 回答