Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting R tables to HTML

Tags:

html

r

export

Is there a way to easily export R tables to a simple HTML page?

like image 363
David B Avatar asked Aug 09 '10 07:08

David B


4 Answers

The xtable function in the xtable package can export R tables to HTML tables. This blog entry describes how you can create HTML pages from Sweave documents.

like image 172
nullglob Avatar answered Oct 05 '22 17:10

nullglob


It might be worth mentioning that there has been a new package specifically designed to convert (and style with css) data.frames (or tables) into HTML tables in an easy and intuitive way. It is called tableHTML. You can see a simple example below:

library(tableHTML)
#create an html table 
tableHTML(mtcars)

#and to export in a file
write_tableHTML(tableHTML(mtcars), file = 'myfile.html')

You can see a detailed tutorial here as well.

like image 23
LyzandeR Avatar answered Oct 03 '22 17:10

LyzandeR


Apart from xtable mentioned by @nullglob there are three more packages that might come handy here:

  • R2HTML
  • HTMLUtils
  • hwriter
like image 26
radek Avatar answered Oct 03 '22 17:10

radek


The grammar of tables package gt is also an option.

Here's the example from the docs for generating a HTML table:

library(gt)

tab_html <-
  gtcars %>%
  dplyr::select(mfr, model, msrp) %>%
  dplyr::slice(1:5) %>%
  gt() %>%
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) %>%
  as_raw_html()
like image 26
sbha Avatar answered Oct 01 '22 17:10

sbha