4

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.

Community
  • 1
  • 1
andrewj
  • 2,965
  • 8
  • 36
  • 37

1 Answers1

9

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)
Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • Thanks, very helpful! Your use use of transform is what did the trick. I can then use `HTML(foo, file='bar.html')` and it displays properly. Additionally, thanks for sharing your tip with `gvisTable`, very nice. Using `print(x, file='bar.html')` gives the desired result. – andrewj Nov 06 '11 at 22:36
  • Question about `gvisTable()`. Is there a way to change the parameters so that the number of rows and columns displayed changes as you resize the browser window? – andrewj Nov 07 '11 at 21:22