我用 R 包 reactable 构建了一个嵌套表,并希望在所有行中搜索,包括最初不可见的第二级。这是代码:
a <- c("x", "a", 5)
b <- c("x", "b", 3)
c <- c("y", "c", 6)
d <- c("y", "d", 1)
e <- c("x", "e", 8)
f <- c("y", "f", 2)
x <- c("x", "x", 4)
y <- c("y", "y", 7)
df <- rbind(a,b,c,d,e,f,x,y)
cols <- c("group", "product", "value")
colnames(df) <- cols
df <- as.data.frame(df)
df$value <- as.numeric(df$value)
y <- df[df$product == "y" | df$product == "x",]
x <- df[!(df$product == "y" | df$product == "x"),]
library(reactable)
reactable(
data = y,
searchable = TRUE,
columns = list(
product = colDef(show = FALSE),
group = colDef(show = FALSE)
),
details = function(index) {
nest = x[x$group == y$product[index], ]
reactable(data = nest,
columns = list(
group = colDef(show = FALSE),
product = colDef(show = FALSE)
)
)
}
)
我尝试不使用本文中描述的索引
但我无法让它工作。我该如何解决这个问题?