I'm using rMarkdown, knitting to html, and trying to do something simple in reactable - use JS to suppress row totals in parentheses. I'm literally copying from their own guide, but its not working:
reactable Grouped Cell Rendering
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
}")
)
)
)
I get the following error:
Error in colDef(grouped = JS("function(cellInfo) {\n return cellInfo.value\n }")) :
unused argument (grouped = JS("function(cellInfo) {\n return cellInfo.value\n }"))
Any help would be much appreciated.
The grouped
argument is not available (yet) on the CRAN version of the package. You can install the development version from github and then the example works.
#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
}")
)
)
)