2017-02-19 63 views
1

我想使用DT和DT內部我想鏈接到rmarkdown文檔的各個部分。我嘗試了下面的代碼,但它不起作用。如何正確鏈接到rmarkdown中的DT部分?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

您應該使用普通的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) 
相關問題