How to insert footnotes in ioslides presentations using RMarkdown - r

I created a ioslides presentation by using the knitr package and it works well. Now I want to insert footnotes on my slides. I did not find any useful posts on SO. Can anyone show me how to add footnotes on R slides? Any idea?
Here is the dummy code chunk:
---
title: "R presentation"
author: "me"
date: "March 9, 2017"
output:
ioslides_presentation
---
## slides one
* content
* introduction
## Content
- Bullet 1
- Bullet 2
- Bullet 3

Martin Schmelzers answer is great, but I was lacking the possibility of formatting text in the footnote (i.e. make text italic or bold for correctly formatting literature references).
I updated his example to allow for this. See the reproducible example below. Footnotes are added like:
<footnote>A *footnote* with **formatting**</footnote>
---
title: "New footnotes"
author: "Emil Tveden Bjerglund"
date: "August 8, 2017"
subtitle: "Inspired by Martin Schmelzer"
output: ioslides_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
<style>
div.footnotes {
position: absolute;
bottom: 0;
margin-bottom: 10px;
width: 80%;
font-size: 0.6em;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('slide:not(.backdrop):not(.title-slide)').append('<div class=\"footnotes\">');
$('footnote').each(function(index) {
var text = $(this).html();
var fnNum = (index+1).toString();
$(this).html(fnNum.sup());
var footnote = fnNum + '. ' + text + '<br/>';
var oldContent = $(this).parents('slide').children('div.footnotes').html();
var newContent = oldContent + footnote;
$(this).parents('slide').children('div.footnotes').html(newContent);
});
});
</script>
## Testing footnotes
Some text.<footnote>And a footnote. http://stackoverflow.com</footnote>
Some more text.<footnote>And *another* **footnote**</footnote>

Here is a workaround. It might not be bullet proof and need further improvements:
Let's start with a fully reproducible example:
---
title: "Footnotes"
author: "Martin Schmelzer"
date: "9 3 2017"
output: ioslides_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
<style>
div.footnotes {
position: absolute;
bottom: 0;
margin-bottom: 10px;
width: 80%;
font-size: 0.6em;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('slide:not(.backdrop):not(.title-slide)').append('<div class=\"footnotes\">');
$('footnote').each(function(index) {
var text = $(this).html();
var fnNum = (index+1).toString().sup();
$(this).html(text + fnNum);
var footnote = fnNum + ': ' + $(this).attr('content') + '<br/>';
var oldContent = $(this).parents('slide').children('div.footnotes').html();
var newContent = oldContent + footnote;
$(this).parents('slide').children('div.footnotes').html(newContent);
});
});
</script>
## Try out some footnotes
Lets assume I have a footnote <footnote content="The first awesoem footnote!">here</footnote>. And here we are going to have another one: <footnote content="This is my second footnote!">#secFN</footnote>
## The Second Topic
See auto numbering for <footnote content = "The counter is not set back and continues on the next slide.">footnotes</footnote>
Now let's see what I have done here:
1. We add some styles for our footnote container at the bottom of each slide.
2. We include the jQuery library.
3. What then follows is the main script:
When the document has finished loading (document.ready()) we select all slides excluding the title slides and the back drop slide. To each of them we add a footnote container (<div class="footnotes"></div>) as the last child.
Afterwards we simply go through the document and search for our footnotes which can be created the following way:
<footnote content="What should be written at the bottom?">Text</footnote>
We select all footnotes and apply a function to each of them which reads out the content of footnote and adds it to the container. The footnotes get autonumbered and the superscripts are added with sup().
This is what the result looks like:

Related

Remove slide number and footer on quarto title slide

Is it possible to remove slide-number and footer elements from the title slide in Quarto?
---
title: "My prez"
format:
revealjs:
slide-number: c
footer: "Confidential"
---
Thanks!
You can do this using Revealjs API methods. So write the necessary Js code (To capture the event of slide being ready and slide changed and if the current slide is title slide, change the display of footer and slide number to none) in a html file and then attach that file to qmd file using include-after-body.
---
title: "My prez"
format:
revealjs:
slide-number: c
footer: "Confidential"
include-after-body: clean_title_page.html
---
## Slide A
## Slide B
clean_title_page.html
<style>
.hide {
display: none !important;
}
</style>
<script>
function remove() {
let footer = document.querySelector('div.footer');
let slideNo = document.querySelector('div.slide-number');
slideNo.classList.add('hide');
footer.classList.add('hide');
Reveal.on('slidechanged', event => {
if(Reveal.isFirstSlide()) {
slideNo.classList.add('hide');
footer.classList.add('hide');
} else {
slideNo.classList.remove('hide');
footer.classList.remove('hide');
}
});
}
window.onload = remove();
</script>

HTML page is left-aligned when specifying the theme to use ( R Markdown - cleanrmd package)

When using the cleanrmd package for R Markdown, the output html page is left-aligned if I specify the theme to use, while it's centered when the them is set as NULL.
theme set as NULL
---
title: "TEST"
output:
cleanrmd::html_document_clean:
theme: NULL
---
With a theme specified
---
title: "TEST"
output:
cleanrmd::html_document_clean:
theme: new.css
---
Anyone can help me to fix this?
Specify CSS rule body { margin: 0 auto; padding: 2rem;} for the entire body of the document, which will fix the issue.
---
title: "Title"
author: "Author"
date: "Date"
output:
cleanrmd::html_document_clean:
theme: new.css
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{css, echo = FALSE}
body {
margin: 0 auto;
max-width: 750px;
padding: 2rem;
}
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax
for authoring HTML, PDF, and MS Word documents. For more details on
using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that
includes both content as well as the output of any embedded R code
chunks within the document.
Rendered output looks like,

R Flexdashboard - add a break in the title

I am new to R markdown. My title for the dashboard is big. I want it to appear like this:
Uber data analysis
(NYC, April 2014 - September 2014)
As of now, it comes out in one line like in the image below:
Please let me know how to fix this. Thanks
I don't know why this isn't easier. A way to hack it is to use the author YAML input as the subtitle and use some css to rearrange the title. If you run the following Rmarkdown file, you should see the title now on two lines.
---
title: "Uber data analysis"
author: "(NYC, April 2014 - September 2014)"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
<style>
.navbar-brand {
display: grid;
margin: auto;
padding: 5px;
}
.navbar-author {
margin-left: 0px;
}
</style>
```{r setup, include=FALSE}
library(flexdashboard)
```
Highlights
========================================
Column
-----------------------------------------------------------------------
### Chart A
```{r}
```

how to number custom blocks in R markdown [duplicate]

Is there an option I can provide to code chunks in RMarkdown so that it will have a cell number attached to the HTML output. Much like Jupyter has cell numbers.
I've seen some example with line numbering which is not what I want.
Using cell numbers is helpful when I'm discussing an RMarkdown HTML file over the phone with someone. I can ask him/her to see cell 23. I have a lot of R code, so providing section titles, while possible, is tedious.
Here's a solution using only CSS. It relies on CSS counters: each new R chunk increments the counter (named counter-rchunks).
You can knit the following minimal Rmd file and get this result:
---
title: "Counter for chunks"
author: "Romain Lesur"
output: html_document
---
```{css, echo=FALSE}
body {
counter-reset: counter-rchunks;
}
div.main-container {
padding-left: 5em;
}
pre.r {
counter-increment: counter-rchunks;
position: relative;
overflow: visible;
}
pre.r::before {
content: 'In [' counter(counter-rchunks) ']: ';
display: inline-block;
position: absolute;
left: -5em;
color: rgb(48, 63, 159);
}
```
```{r cars}
summary(cars)
```
```{r head-cars}
head(cars)
```
You may have to adapt this solution to your HTML template.
You also can insert these CSS rules to a .css file and includes it in your html_document.

Display a data frame as table in R Markdown

In knitr I want to add a (small) data frame as a table using the kable package:
---
output: html_document
---
```{r}
knitr::kable(mtcars[1:5,1:5], format="html")
```
This returns a compact table as above, while changing it to format="markdown"returns a nice table but spanning the whole page:
I have found the knitr manual but it does not cover the extra formatting options for each format. How can I change the size of a knitr table or even better, where can I get this information from?
The general approach would be to use your own custom CSS and include that in the YAML at the start of the document.
You can actually sort of do this from within your document, but I would suggest editing your CSS outside of the document and working from there.
Here's a minimal example:
---
title: "Test"
date: "24 October 2015"
output:
html_document:
css: mystyle.css
---
```{r, results='asis'}
writeLines("td, th { padding : 6px } th { background-color : brown ; color : white; border : 1px solid white; } td { color : brown ; border : 1px solid brown }", con = "mystyle.css")
dset1 <- head(ToothGrowth)
knitr::kable(dset1, format = "html")
```
This should:
Create a file named "mystyle.css" with your relevant CSS styling.
Produce something that looks something like the following.

Resources