2011-11-06 71 views
3

爲HTML雖然這個問題更普遍已在這裏看到:R中導出錶鏈接

Exporting R tables to HTML

我特別想知道如何在數據幀的文本顯示爲超鏈接。 html文件。我正在使用R2HTML包。

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') 

在上述例子中,我想的http://nytimes.com等,以顯示爲foo.html文件的超鏈接。

道歉,如果我失去了明顯的東西。

回答

8

下面是使用googleVis

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

感謝的解決方案,非常有幫助!你使用變換是訣竅。然後我可以使用HTML(foo,file ='bar.html')'並且它可以正確顯示。此外,感謝您與'gvisTable'分享您的提示,非常好。使用'print(x,file ='bar.html')'可以得到想要的結果。 – andrewj

+0

關於'gvisTable()'的問題。有沒有辦法更改參數,以便在調整瀏覽器窗口大小時顯示行數和列數? – andrewj