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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745281551a4620305.html
评论列表(0条)