Loop, hide columns and r formattable

余生长醉 提交于 2020-02-05 09:24:57

问题


I have this

A<-1:10
B<-10:1
C<-11:20
df<-data.frame(id=1:10,A,B,C,tA=A>5,tB=B>5)

I'm using formattable and this is what I would like to have (Output 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))

The problem is I would like to loop for columns A and 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))
        }
        ))

The question: How to combine lapply and formattable to have like in Output 1?

Many thanks.

来源:https://stackoverflow.com/questions/53308518/loop-hide-columns-and-r-formattable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!