【问题标题】:Putting hyperlinks into an HTML table in R将超链接放入 R 中的 HTML 表中
【发布时间】:2013-06-13 20:54:16
【问题描述】:

我是一名试图做计算机科学研究的生物学家,所以我可能有点天真。但我想制作一个包含来自数据框的信息的表格,其中一列中有一个超链接。我想这需要是一个 html 文档(?)。我发现这篇文章this post 描述了如何将超链接放入数据框中并使用 googleVis 将其写为 HTML 文件。我想使用这种方法(这是我知道的唯一一种方法,而且似乎效果很好),但我想用描述替换实际的 URL。真正的动机是我想包含许多这些超链接,而且这些链接的地址很长,难以阅读。

为了冗长,我基本上想做我所做的here,我们读到“这里”但“这里”指向 http://stackoverflow.com/questions/8030208/exporting-table-in-r-to-html-with-hyperlinks

【问题讨论】:

    标签: html r hyperlink html-table


    【解决方案1】:

    根据您之前的问题,您可以有另一个列表,其中包含 URL 的标题:

    url=c('http://nytimes.com', 'http://cnn.com', 'http://www.weather.gov'))
    urlTitles=c('NY Times', 'CNN', 'Weather'))
    
    foo <- transform(foo, url = paste('<a href = ', shQuote(url), '>', urlTitles, '</a>')) 
    x = gvisTable(foo, options = list(allowHTML = TRUE))
    plot(x)
    

    【讨论】:

      【解决方案2】:

      以 Jack 的回答为基础,但从不同的线程中整合:

      library(googleVis)
      library(R2HTML)
      url <- c('http://nytimes.com', 'http://cnn.com', 'http://www.weather.gov')
      urlTitles <- c('NY Times', 'CNN', 'Weather')
      foo <- data.frame(a=c(1,2,3), b=c(4,5,6), url=url)
      foo <- transform(foo, url = paste('<a href = ', shQuote(url), '>', urlTitles, '</a>')) 
      x   <- gvisTable(foo, options = list(allowHTML = TRUE))
      plot(x)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-26
        • 1970-01-01
        • 1970-01-01
        • 2021-06-12
        • 1970-01-01
        • 1970-01-01
        • 2019-03-24
        相关资源
        最近更新 更多