循环,隐藏列和r formattable

时间:2018-11-14 20:51:03

标签: r formattable

我有这个

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结合在一起?

非常感谢。

0 个答案:

没有答案