formattable example

| category RStudy  | tag table 
library(formattable)
df <- data.frame(
    Disease=c("BD","BD","CAD","CD","CD","RA","RA","T1D","T2D"),
    K=c(0.0045, 0.01, 0.056,0.0005,0.001,0.0075,0.011,0.0054,0.028),
    NO.SigSNP=c(0,0,13,26,26,3,3,43,10),
    VE=c(NA,NA,0.0091,0.0148, 0.0164,0.0205,0.0219,0.1265,0.0051),
    SampleSize = c(2000,2000,10000,1999,1999,3001,3001,4000,999),
    Tested = c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,FALSE,TRUE),
    Grade=c("A","A","B","C","C","B","B","A","C"),
    Score=c(8.9,8.9,9.1,9.9,9.9,9.5,9.5,4.3,1.6)
)
formattable(df)
Disease K NO.SigSNP VE SampleSize Tested Grade Score
BD 0.0045 0 NA 2000 TRUE A 8.9
BD 0.0100 0 NA 2000 TRUE A 8.9
CAD 0.0560 13 0.0091 10000 FALSE B 9.1
CD 0.0005 26 0.0148 1999 FALSE C 9.9
CD 0.0010 26 0.0164 1999 FALSE C 9.9
RA 0.0075 3 0.0205 3001 TRUE B 9.5
RA 0.0110 3 0.0219 3001 TRUE B 9.5
T1D 0.0054 43 0.1265 4000 FALSE A 4.3
T2D 0.0280 10 0.0051 999 TRUE C 1.6
df2 <- df
df2$K <- percent(df2$K)
df2$SampleSize <- accounting(df2$SampleSize,format="d")
df2$Tested <- formattable(df2$Tested, "yes","no")
formattable(df2)
Disease K NO.SigSNP VE SampleSize Tested Grade Score
BD 0.45% 0 NA 2,000 yes A 8.9
BD 1.00% 0 NA 2,000 yes A 8.9
CAD 5.60% 13 0.0091 10,000 no B 9.1
CD 0.05% 26 0.0148 1,999 no C 9.9
CD 0.10% 26 0.0164 1,999 no C 9.9
RA 0.75% 3 0.0205 3,001 yes B 9.5
RA 1.10% 3 0.0219 3,001 yes B 9.5
T1D 0.54% 43 0.1265 4,000 no A 4.3
T2D 2.80% 10 0.0051 999 yes C 1.6
formattable(df, list(
  K = formatter("span",
                    style=x~style(color=ifelse(rank(-x)<=3,"red","gray")),
                    x~sprintf("%.4f (rank: %2d)", x, rank(-x))
                    ),
  Tested = formatter("span",
                     style=x~style(color=ifelse(x,"green","red")),
                     x~icontext(ifelse(x,"ok","remove"),ifelse(x,"yes","no"))
                     ),
  Grade = formatter("span", style=x~ifelse(x=="A",style(color="red",font.weight="bold"),NA)),
  Score = color_bar("pink", 0.5)
))
Disease K NO.SigSNP VE SampleSize Tested Grade Score
BD 0.0045 (rank: 7) 0 NA 2000 yes A 8.9
BD 0.0100 (rank: 4) 0 NA 2000 yes A 8.9
CAD 0.0560 (rank: 1) 13 0.0091 10000 no B 9.1
CD 0.0005 (rank: 9) 26 0.0148 1999 no C 9.9
CD 0.0010 (rank: 8) 26 0.0164 1999 no C 9.9
RA 0.0075 (rank: 5) 3 0.0205 3001 yes B 9.5
RA 0.0110 (rank: 3) 3 0.0219 3001 yes B 9.5
T1D 0.0054 (rank: 6) 43 0.1265 4000 no A 4.3
T2D 0.0280 (rank: 2) 10 0.0051 999 yes C 1.6

Previous     Next