0

使用 reactable 包,可扩展行是使用 R 函数有条件的function(index)。如果返回值不为 NULL,则该行是可扩展的。

是否可以使用 javascript 渲染函数做同样的事情?

这里有两个表,第一个用 R 渲染,第二个用 javascript 渲染。两个表几乎相同,第二个表的每一行都有扩展图标,而我希望它只有满足条件的行的扩展图标。

library(reactable)
library(shiny)

df <- iris[1:5,]

# This table has two expandable rows
reactable(df, details = function(index) {
  if (df$Sepal.Length[index] >= 5) {
    "Greater or equal to 5"
  }
})

# This table has five expandable rows, but should only have two
reactable(df, details = JS("function(rowInfo){
  if(rowInfo.row['Sepal.Length'] >= 5){
    return 'Greater or equal 5';
  };
}"))

这个用 R 函数渲染 第一张桌子

这个使用 javascript 函数呈现 - 想要删除那些不必要的展开图标,使其看起来与第一个表相同。 第二张桌子

4

0 回答 0