链接到rmarkdown中DT的部分

时间:2017-02-19 09:56:04

标签: r r-markdown dt

我想使用DT和DT内部我希望链接到rmarkdown文档的各个部分。我尝试了下面的代码,但它不起作用。如何在rmarkdown中正确链接DT中的部分?

---
title: "Test links to sections in DT"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE)
```

## DT

How to make links work in DT in rmarkdown?

```{r echo=FALSE}
library(DT)
testDF <- data.frame(text=paste0("Section", 1:5), 
                     linksTest1=paste0("[", "Section", 1:5, "]", "(#Section", 1:5, ")"))
datatable(testDF, rownames=FALSE, escape=FALSE)
```

## Section 1 {#Section1}

Section 1

## Section 2 {#Section2}

Section 2

## Section 3 {#Section3}

Section 3

## Section 4 {#Section4}

Section 4

## Section 5 {#Section5}

Section 5

1 个答案:

答案 0 :(得分:1)

您应该使用普通的HTML超链接标记,而不是降价:

library(DT)
testDF <- data.frame(text=paste0("Section", 1:5), 
                     linksTest1=paste0("<a href=#Section", 1:5, ">Section", 1:5, "</a>"))
datatable(testDF, rownames=FALSE, escape=FALSE)