问题
I am creating a user interface for a pathway enrichment program. The results are shown in a table as shown below.
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:
Modify the last column so that the KEGGLINK is changed into a proper HTML link that looks like:
<a href='url'>link text</a>
.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