0

我正在使用 {reactable} 在 R 中创建一个表。
我正在使用的数据按物种分组我希望当我展开组行时,我可以获得组的详细信息。
{reactable} 文档中的示例仅显示如何按 ROW 索引提供详细信息。
我如何定位 GROUP 而不是行?

谢谢您的帮助。

这是一个例子:

library(dplyr)

iris2 <- iris %>% 
  mutate(
    group_info = case_when(
      
      Species == "setosa" ~ "Info about the setosa group", 
      Species == "versicolor" ~ "Info about the versicolor group", 
      Species == "virginica" ~ "Info about the virginica group"
      
    )
  ) %>% 
  group_by(Species)



reactable(iris2, groupBy = "Species", details = colDef(
  name = "More",
  
  # i need to use the GROUP index, not the ROW index, however not sure how to implement this, would like the group_info to show on clicking/expanding the group
  
  details = JS("function(rowInfo) {  
    return 'Details for row: ' + rowInfo.index +
      '<pre>' + JSON.stringify(rowInfo.row, null, 2) + '</pre>'
  }"),
  html = TRUE,
  width = 60

))
4

0 回答 0