我有这个
A<-1:10
B<-10:1
C<-11:20
df<-data.frame(id=1:10,A,B,C,tA=A>5,tB=B>5)
我正在使用 formattable,这就是我想要的(输出 1)
formattable(df, list(
id = formatter("span",
style = ~ style(color = "gray")),
A=formatter("span",
style = ~ style(color = ifelse(tA==TRUE, "green", "red")),
~ icontext(ifelse(tA==TRUE, "arrow-up", "arrow-down"), A)),
B=formatter("span",
style = ~ style(color = ifelse(tB==TRUE, "green", "red")),
~ icontext(ifelse(tB==TRUE, "arrow-up", "arrow-down"), B)),
C=color_tile("transparent", "lightpink"),
tA=FALSE,
tB=FALSE))
问题是我想循环A列和B列。
formattable(df,
lapply(df[,c("A","B")], function(col)
{
col=formatter("span",
style = x ~ style(color = ifelse(x>XXX, "green", "red")),
x ~ icontext(ifelse(x>val[1], "arrow-up", "arrow-down"), x))
}
))
问题:如何在输出 1 中结合 lapply 和 formattable ?
非常感谢。