R笔记本HTML格式-向分页表添加超链接

R笔记本HTML格式-向分页表添加超链接,r,hyperlink,html-table,r-markdown,rnotebook,R,Hyperlink,Html Table,R Markdown,Rnotebook,我想从一个R笔记本中编织一个html文件,其中包含带超链接的分页表格。 可以使用knitr::kable插入超链接,但我找不到使用此函数生成分页的表的方法。 分页表格是默认的笔记本输出,但我找不到插入功能性超链接的方法。非常感谢你的帮助 --- title: "Paged notebook table with hyperlinks" output: html_notebook: code_folding: "hide" --- ```{r rows.print=3} wiki.u

我想从一个R笔记本中编织一个html文件,其中包含带超链接的分页表格。
可以使用
knitr::kable
插入超链接,但我找不到使用此函数生成分页的表的方法。
分页表格是默认的笔记本输出,但我找不到插入功能性超链接的方法。非常感谢你的帮助

---
title: "Paged notebook table with hyperlinks"
output:
  html_notebook:
    code_folding: "hide"
---

```{r rows.print=3}
wiki.url <- "https://en.wikipedia.org/wiki/"
df1 <- data.frame(Month=month.name, URL=paste0("[", month.name, "](", wiki.url, month.name, ")"))
df2 <- data.frame(Month=month.name, URL=paste0("<a href='", wiki.url, month.name, "'>", month.name, "</a>"))
print(df1)
```

```{r rows.print=3}
print(df2)
```

```{r rows.print=3}
knitr::kable(df1)
```

```{r rows.print=3}
knitr::kable(df2)
```
---
标题:“带超链接的分页笔记本表”
输出:
html_笔记本:
代码折叠:“隐藏”
---
```{r rows.print=3}

wiki.url既然我的问题似乎没有一个完美的解决方案,我想我应该发布我想出的解决方法——以防有人有类似的问题。
我用
knitr::kable
创建了表和超链接,然后添加了一个html按钮并切换可见性-虽然没有分页表那么优雅,但可以完成这项工作。
请注意默认情况下表格所在文件底部的
标记。
(将代码粘贴到RStudio中的.Rmd文件中):

---
标题:“在html笔记本中使用超链接管理大型表”
输出:
html_笔记本:
代码折叠:“隐藏”
---
函数myFunction(id){
var x=document.getElementById(id);
如果(x.style.display=='none'){
x、 style.display='block';
}否则{
x、 style.display='none';
}
}
```{r}
图书馆(knitr)
df1
---
title: "Managing large tables with hyperlinks in html notebook"
output:
  html_notebook:
    code_folding: "hide"
---

<script>
function myFunction(id) {
    var x = document.getElementById(id);
    if (x.style.display === 'none') {
        x.style.display = 'block';
    } else {
        x.style.display = 'none';
    }
}
</script>

```{r}
library(knitr)
df1 <- data.frame(Month=month.name, Link=paste0("[", month.name, "](https://en.wikipedia.org/wiki/", month.name, ")"))
```

<button class="button" onclick="myFunction('DIV_months')">Show/hide table</button>
<div id="DIV_months" class="div_default_hide">
```{r}
knitr::kable(df1)
```
</div>

<script>
var divsToHide = document.getElementsByClassName("div_default_hide");
for(var i = 0; i < divsToHide.length; i++)
    {
    divsToHide[i].style.display = 'none';
    }
</script>