formattable
by Kun Ren and Kenton Russell provides some intuitive functions to create good looking tables for the R console or HTML quickly. The package home page demonstrates the functions with illustrative examples nicely.There are a few points I really like:
- the functions
accounting, currency, percent
transform numbers into better human readable output - cells can be highlighted by adding color information
- contextual icons can be added, e.g. from Glyphicons
- output can be displayed in RStudio's viewer pane
The CRAN Task View: Reproducible Research lists other packages as well that help to create tables for web output, such as compareGroups, DT, htmlTable, HTMLUtils, hwriter, Kmisc, knitr, lazyWeave, SortableHTMLTables, texreg and ztable. Yet, if I am not mistaken, most of these packages focus more on generating complex tables with multi-columns rows, footnotes, math notation, etc, than the points I mentioned above.
Finally, here is a little
formattable
example from my side:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(formattable) | |
DF <- data.frame(Ticker=c("", "", "", "IBM", "AAPL", "MSFT"), | |
Name=c("Dow Jones", "S&P 500", "Technology", | |
"IBM", "Apple", "Microsoft"), | |
Value=accounting(c(15988.08, 1880.33, NA, | |
130.00, 97.05, 50.99)), | |
Change=percent(c(-0.0239, -0.0216, 0.021, | |
-0.0219, -0.0248, -0.0399))) | |
DF | |
## Ticker Name Value Change | |
## 1 Dow Jones 15,988.08 -2.39% | |
## 2 S&P 500 1,880.33 -2.16% | |
## 3 Technology NA 2.10% | |
## 4 IBM IBM 130.00 -2.19% | |
## 5 AAPL Apple 97.05 -2.48% | |
## 6 MSFT Microsoft 50.99 -3.99% | |
formattable(DF, list( | |
Name=formatter( | |
"span", | |
style = x ~ ifelse(x == "Technology", | |
style(font.weight = "bold"), NA)), | |
Value = color_tile("white", "orange"), | |
Change = formatter( | |
"span", | |
style = x ~ style(color = ifelse(x < 0 , "red", "green")), | |
x ~ icontext(ifelse(x < 0, "arrow-down", "arrow-up"), x))) | |
) |
Session Info
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] formattable_0.1.5
loaded via a namespace (and not attached):
[1] shiny_0.12.2.9006 htmlwidgets_0.5.1 R6_2.1.1
[4] rsconnect_0.3.79 markdown_0.7.7 htmltools_0.3
[7] tools_3.2.3 yaml_2.1.13 Rcpp_0.12.2
[10] highr_0.5.1 knitr_1.12 jsonlite_0.9.19
[13] digest_0.6.9 xtable_1.8-0 httpuv_1.3.3
[16] mime_0.4
Terimaksih atas informasinya....
ReplyDeleteby : Baja Ringan Jakarta dan Baja Ringan Jakarta serta Baja Ringan Jakarta | Baja Ringan Jakarta Thanks for all