在 Shiny 中将一列文本 URL 转换为活动超链接 [英] Convert a column of text URLs into active hyperlinks in Shiny

查看:38
本文介绍了在 Shiny 中将一列文本 URL 转换为活动超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为通路丰富计划创建用户界面.结果如下表所示.

I am creating a user interface for a pathway enrichment program. The results are shown in a table as shown below.

下面是一个片段,显示我正在使用 DT::renderDataTable 和 DT::datatable 在选项卡中输出表格.spia_out() 只是一个反应性函数,用于运行通路富集并生成数据框.

Below is a snippet showing that I am using DT::renderDataTable and DT::datatable to output the table in a tab. spia_out() is just a reactive function that runs the pathway enrichment and produces a dataframe.

spia_out <- reactive({
    ...get results in a dataframe...
  })

output$spiaout <- DT::renderDataTable({
      DT::datatable(spia_out(), extensions = ..., options = ...)
  })

一切正常,生成通路富集表&打印在相应的 UI 元素中.我唯一的问题是如何将 URL 的最后一列 (KEGGLINK) 转换为活动超链接?这样人们就可以点击它们而不是复制&粘贴.

Everything works fine, the pathway enrichment table is generated & printed in the corresponding UI element. My only problem is how to convert the last column (KEGGLINK) of URLs into active hyperlinks? So that people can just click on them instead of copy & pasting.

提前为屏幕截图的大小道歉.我希望你能看到最后一列 KEGGLINK 有 URL,但它们不是活动的.

Apologies in advance for the screenshot's size. I hope you can see the last column KEGGLINK has URLs but they are not active.

推荐答案

你需要做两件事:

  1. 修改最后一列,将 KEGGLINK 更改为正确的 HTML 链接,如下所示:<a href='url'>link text</a>.

向 DT 传递 escape = FALSE 参数,使其不会转义 HTML 代码.

Pass DT the escape = FALSE argument so that it doesn't escape the HTML code.

DT 网页在第 2.9 节中有一个示例:https://rstudio.github.io/DT/

The DT web page has an example of this in section 2.9: https://rstudio.github.io/DT/

#1 的简单方法如下:

A simple way to do #1 would be something like:

mydata$url <- paste0("<a href='",mydata$url,"'>",mydata$url,"</a>")

这篇关于在 Shiny 中将一列文本 URL 转换为活动超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆