Convert a column of text URLs into active hyperlinks in Shiny

旧城冷巷雨未停 提交于 2020-05-24 08:48:09

问题


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

enter image description here

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 = ...)
  })

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.

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:


You need to do two things:

  1. Modify the last column so that the KEGGLINK is changed into a proper HTML link that looks like: <a href='url'>link text</a>.

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

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

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

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


来源:https://stackoverflow.com/questions/30901027/convert-a-column-of-text-urls-into-active-hyperlinks-in-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!