ho recentemente aggiunto questa funzionalità per la mia funzione htmlTable() nel Gmisc-package e la funzione è piuttosto semplice:
print.htmlTable<- function(x, useViewer = TRUE, ...){
# Don't use viewer if in knitr
if (useViewer &&
!"package:knitr" %in% search()){
htmlFile <- tempfile(fileext=".html")
htmlPage <- paste("<html>",
"<head>",
"<meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\">",
"</head>",
"<body>",
"<div style=\"margin: 0 auto; display: table; margin-top: 1em;\">",
x,
"</div>",
"</body>",
"</html>", sep="\n")
cat(htmlPage, file=htmlFile)
viewer <- getOption("viewer")
if (!is.null(viewer) &&
is.function(viewer)){
# (code to write some content to the file)
viewer(htmlFile)
}else{
utils::browseURL(htmlFile)
}
}else{
cat(x)
}
}
RStudio recommends di utilizzare il getOption ("viewer") al posto di @ suggerimento di Ramnath, il grezzo RStudio :: viewer(). La mia soluzione aggiunge anche utils :: browserURL() nel caso in cui non si utilizzi RStudio. Ho avuto l'idea dal post del blog this.
fonte
2014-04-04 19:07:14
Penso che tu possa convertire il tuo oggetto in una grigliaTable grob nel pacchetto 'gridExtra' e tracciare quello (vedi ad esempio http://stackoverflow.com/questions/15045396/r-suppressing-rownames-in-grid-table). –
Bel trucco ma non è un tavolo HTML. – PAC