The idea is to :
- Create a css where you format "stylize" your table using some css features
- Create a html table using
print.xtable
- Create a file including a link to the css file and the created html table
So here the code creating the "res.html" file:
## a dummy data.frame used as an example
library(xtable)
n <- data.frame(x = c(1,1,1,1,1), y = c(0,1,0,1,0))
## the html header
## here I am using a link to mystyle.css
html.head <- paste("<head>" ,
'<link rel="stylesheet" type="text/css" href="mystyle.css"/>',
"</head>",sep='\n')
## the html body
html.table <- paste(print(xtable(n),type='html','res.html'),
collapse = "\n")
html.body <- paste("<body>", html.table,"</body>")
## the html file
write(paste(html.head,html.body,sep='\n'),"res.html")
the syle sheet file(mystyle.css) can contain be something like this :
table {
max-width: 95%;
border: 1px solid #ccc;
}
th {
background-color: #000000; // background for table header
color: #ffffff;
}
td
{
text-align:right; // justify column
background-color: #FF0000;
}