admin管理员组文章数量:1418113
I have this code from an R markdown file which generates a popover. And it's working as expected:
For the R markdown document you need library(rmarkdown)
, library(pandoc)
and pandoc_activate()
. You render it with: rmarkdown::render("C:/YourPath/Popover.Rmd")
Popover.Rmd
---
title: "Test Popover"
date: "Last edited: `r format(Sys.time(), '%d.%m.%Y')`"
output: html_document
---
<script>
$(document).ready(function(){
// Get the text from the other element
var textTag_1 = $('#Tag_1-source').text();
var textTag_2 = $('#Tag_2-source').text();
// Set the popover content dynamically
$('#Tag_1').attr('data-content', textTag_1);
$('#Tag_2').attr('data-content', textTag_2);
// Initialize popover
$('[data-toggle="popover"]').popover({ trigger: "hover" });
});
</script>
# Tag definition
I want to define my tags, which I want to use:
- Keyword_Tag_1
- <p id="Tag_1-source">
Tag 1 describes...</p>
- Keyword_Tag_2
- <p id="Tag_2-source">
Tag 2 is all about...</p>
# Flowers
Flowers are ...
This section is taged with the following tags:
<a id="Tag_1"
data-toggle="popover"
data-placement="top"
data-content="Initial">
Keyword_Tag_1</a>,
<a id="Tag_2"
data-toggle="popover"
data-placement="top"
data-content="Initial">
Keyword_Tag_2</a>
See the rendered result:
Challenge: Now I want the same in a bookdown document, but it's not working. I want to define the Keyword_Tag_1, Keyword_Tag_2... in file index.Rmd and in file section1.Rmd I have some text where I want to add my tags.
Question: Perhaps you can use my skeleton and figure out what has to be added / corrected.
Here you need additional packages: library(bookdown)
, library(knitr)
, library(markdown)
and library(tinytex)
You render it with: bookdown::render_book("C:/YourPath/index.Rmd", output_format = "bookdown::gitbook")
index.Rmd
---
title: "Popover in Bookdown"
date: "Last edited: `r format(Sys.time(), '%d.%m.%Y')`"
output: bookdown::gitbook
---
<script>
$(document).ready(function(){
// Get the text from the other element
var textTag_1 = $('#Tag_1-source').text();
var textTag_2 = $('#Tag_2-source').text();
// Set the popover content dynamically
$('#Tag_1').attr('data-content', textTag_1);
$('#Tag_2').attr('data-content', textTag_2);
// Initialize popover
$('[data-toggle="popover"]').popover({ trigger: "hover" });
});
</script>
# Tag definition
I want to define my tags, which I want to use:
- Keyword_Tag_1
- <p id="Tag_1-source">
Tag 1 describes...</p>
- Keyword_Tag_2
- <p id="Tag_2-source">
Tag 2 is all about...</p>
section1.Rmd
# Flowers
Flowers are ...
This section is taged with the following tags:
<a id="Tag_1"
data-toggle="popover"
data-placement="top"
data-content="Initial">
Keyword_Tag_1</a>,
<a id="Tag_2"
data-toggle="popover"
data-placement="top"
data-content="Initial">
Keyword_Tag_2</a>
本文标签: r markdownInsert a popover in R Bookdown documentStack Overflow
版权声明:本文标题:r markdown - Insert a popover in R Bookdown document - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745281551a2651450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论