One possibility to do this is shown in the code below:
when formatting the link column convert the url to a hyperlink to that url with the same reference text.
We can do that by using the fmt function to format the link column with the make_hyperlink function.
Knitting the following Rmd file
---
title: "Untitled"
author: "My name"
date: "6/18/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(gt)
make_hyperlink = function(myurl,mytext=myurl) {
paste('<a href="',myurl,'">',mytext,'</a>')
}
df <- data.frame(
stringsAsFactors = FALSE,
country = c("UK", "US"),
name = c("BBC", "CNN"),
link = c("https://www.bbc.com/news", "https://edition.cnn.com/")
)
df %>%
gt() %>%
fmt (
columns = 'link',
fns = make_hyperlink
)
```
creates a html document with the code (not shown here) and the following table:
