andrewj
andrewj

Reputation: 3057

exporting table in R to HTML with hyperlinks

While this question more generally has been looked at here:

Exporting R tables to HTML

I was wondering specifically how to have text in a data frame appear as a hyperlink in the .html file. I am using the R2HTML package.

foo <- data.frame(a=c(1,2,3), b=c(4,5,6), 
url=c('http://nytimes.com', 'http://cnn.com', 'http://www.weather.gov'))


HTML(foo, file='foo.html')

In the above example, I'd like the http://nytimes.com, etc. to appear as hyperlinks in the foo.html file.

Apologies if I am missing something obvious.

Upvotes: 4

Views: 1520

Answers (1)

Ramnath
Ramnath

Reputation: 55735

Here is a solution using googleVis

foo <- transform(foo, url = paste('<a href = ', shQuote(url), '>', url, '</a>')) 
x = gvisTable(foo, options = list(allowHTML = TRUE))
plot(x)

Upvotes: 9

Related Questions