Inserting links to sections and webpages in Bookdown table

Hi,

Is it possible to embed a hyperlink to sections in a bookdown document and to webpages in a table?

(Apologies for the lack of proper repex, but not sure how to create one for a multiple file problem like bookdown)

I have tried to embed a DT table in a bookdown document that has links to sections and websites but haven't managed to get it to work - code below

Any pointers greatly recieved,

Thanks

Iain

library(DT)
library(dplyr)

#section link is the anchor name in the document that I am hoping to reference using \@ref()
my_data<-tibble(section=c('introduction','Chapter two'),section_link=c('intro','section_two'), 
weblink=c('www.google.com','www.bing.com'))

# This code seems to break my bookdown rendering 
#my_data<-my_data%>%
#  mutate(markdown_link=paste0('@ref(',section_link,')'))%>%
#  mutate(hyperlink=paste0("<a href='", weblink,"' target='_blank' class='btn btn-link'>", "Link to weblink","</a>"))

DT::datatable(my_data,escape=FALSE)

Using kable, I am able embed a weblink, but not a section link.

x <- cars[1:3,]
urls <- c("stackoverflow.com", "stats.stackexchange.com", "homebrew.stackexchange.com")
linkID <- c("link1", "link2", "link3")
x$website <- paste0("[", linkID, "](http://", urls, ")")
sections<-c("intro","section_two","section_three")
section_links<-paste0("\\\\@ref(",sections,")")
x$my_sections<-paste0("[", section_links, "](http://",section_links,")")
knitr::kable(x, caption = 'Example table', booktabs = TRUE)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.