Mermaid (diagrammeR) graph not displayed in RPres - r

I am trying to include a graph built with the diagrammeR package in an RPres. That's the graph:
library(DiagrammeR)
mermaid("graph TD
X1(X1)-->Z1(Z2)
X2(X2)-->Z2(Z2)
X1(X1)-->Z2(Z2)
Z1(Z1)-->Y(Y)
Z2(Z2)-->Y(Y)
")
Looking at the output in RStudio's viewer pane is no problem. No I include it in an RPres:
Untitled
========================================================
author:
date:
autosize: true
First Slide
========================================================
```{r,echo=FALSE, results = "asis"}
library(DiagrammeR)
mermaid("graph TD
X1(X1)-->Z1(Z2)
X2(X2)-->Z2(Z2)
X1(X1)-->Z2(Z2)
Z1(Z1)-->Y(Y)
Z2(Z2)-->Y(Y)
")
(note that the "```" to close the code chunk aren't displayed here because of markup...)
Alas, nothing but the abyss of emptiness:

Are you committed to RPres or would you consider alternative slide formats? For example, if you create a new R Markdown document and specify output: ioslides_presentation in the YAML header, the diagram will render properly:
---
title: "Untitled"
author: "Your Name"
date: "5/2/2020"
output: ioslides_presentation
---
Untitled
===========================================================
Here is the content for the second slide in different style
## Title of Mermaid Slide
```{r,echo=FALSE, results = "asis"}
library(DiagrammeR)
mermaid("graph TD
X1(X1)-->Z1(Z2)
X2(X2)-->Z2(Z2)
X1(X1)-->Z2(Z2)
Z1(Z1)-->Y(Y)
Z2(Z2)-->Y(Y)
")
Which produces this:

Related

How do I reduce/remove space between list items in my R Markdown code?

Okay, so I am knitting my R Markdown to a Word document and want to remove the whitespace available between the list items as much as possible.
The code I'm using is :
- The first line.
- The second line.
- The third line.
Can anyone help? Thanks in advance.
We can do this with CSS inside Rmarkdown! just add a CSS chunk and you can control the body of text, or any other desired text.
---
title: "Rmarkdown page"
output: html_document
---
```{css echo = FALSE}
body {line-height: 5;}
```
- item 1
- item 2
- item 3
---
title: "Rmarkdown page"
output: html_document
---
```{css echo = FALSE}
body {line-height: .8;}
```
- item 1
- item 2
- item 3

How can I separate the title page from the table of contents in a RMarkdown Word output?

How can I separate the title page from the table of contents in a RMarkdown Word output? I've seen a lot on here about pdf and html output, but not much about Word. I've tried to use a little bit of LaTex, but it seems that most of that only works with pdf output, and the bit that does work with Word doesn't do what I'm looking for.
---
title: "Sample Title"
subtitle: "Sample Subtitle"
date: "April 8, 2020"
output:
word_document:
toc: yes
---
\newpage
# Header 1
sample text
## Header 2
more sample text
# Another Header 1
loren ipsum
## Another Header 2
foo bar
This just puts a blank page after the table of contents, not before. It feels like there is something simple that I'm missing.
You may consider exploring the officedown package and its block_toc function (together with <!---CHUNK_PAGEBREAK---> inline yaml):
---
title: "Sample Title"
subtitle: "Sample Subtitle"
date: "April 8, 2020"
output:
officedown::rdocx_document
---
<!---CHUNK_PAGEBREAK--->
# Table of Contents
`r officedown::block_toc(level = 5, style = NULL, separator = ";")`
<!---CHUNK_PAGEBREAK--->
# Header 1
sample text
## Header 2
more sample text
# Another Header 1
loren ipsum
## Another Header 2
foo bar
Or even simple, as discussed here:
<!---CHUNK_PAGEBREAK--->
# Table of Contents
<!---BLOCK_TOC--->
<!---CHUNK_PAGEBREAK--->
To place the toc wherever needed without messing with tex files (here with a pdf output),
Turn off automatic toc insertion first in the YAML metadata.
---
title: "myTitle"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: no
number_sections: true
urlcolor: blue
editor_options:
chunk_output_type: console
documentclass: report
---
Then, wherever you want the toc to be in your document, add
```
{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```
You can then place this toc anywhere using latex macros such as \newpage or \hfill\break for example.
---
title: "myTitle"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: no
number_sections: true
urlcolor: blue
editor_options:
chunk_output_type: console
---
\newpage
```{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```
\newpage
Note: documentclass: report in the metadata will automatically separate the toc from the title, but won't allow to separate it from the remainder of the document.
Source

xaringan slide separator not separating slides

In this example xaringan presentation, why are both the ## blank page and the leaflet map on the same slide, given I've separated them by the new-slide separator --- ?
---
title: "map test"
output:
xaringan::moon_reader:
css: ["default"]
nature:
highlightLines: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## blank page
content
---
leaflet page
```{r}
library(leaflet)
leaflet() %>%
addTiles()
```
---
Looks like you've got an unintended space after the new slide separator after blank content as "--- ". Remove that space and it'll be recognized as real slide separator:
---
title: "map test"
output:
xaringan::moon_reader:
css: ["default"]
nature:
highlightLines: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## blank page
content
---
leaflet page
```{r}
library(leaflet)
leaflet() %>%
addTiles()
```
---
In my case I'm adding mathjax/latex equations and I had:
$$
\begin{aligned} P(Y= k)=\comb{k-1}{r-1} * p^r q^{k-r}, \qquad k= r,r+1
\end{aligned}\label{pascal}\tag{5}
$$
And I had to remove the breaklines
$$\begin{aligned} P(Y= k)=\comb{k-1}{r-1} * p^r q^{k-r}, \qquad k= r,r+1
\end{aligned}\label{pascal}\tag{5}$$
and then it worked. I've that it renders mathjax better if all the code is in a single line.

R flexdashboard remove title bar

I am working on a project using rMarkdown and the flexdashboard package from rStudio. Everything is coming together nicely. But I would like to remove the blue title bar you see at the top of the image here.
We are dropping this html page into a window so it becomes a second title bar, which looks terrible. Is there a function in flexdashboard to remove this entire apparatus?
Here is the YAML and the first chunk you see just below the blue bar in the photograph. Any suggestion would be greatly appreciated.
---
title: New Hampshire Statewide Age Adjusted Incedence Rates of Lyme
output:
flexdashboard::flex_dashboard:
orientation: rows
---
```{r setup, include=FALSE, message=FALSE, warning=FALSE, echo=TRUE}
```
Row
-----------------------------------------------------------------------
###
```{r, aarState, message=FALSE, warning=FALSE}
library(flexdashboard)
library(rbokeh)
#load state-wide age adjusted rates
aar<-read.csv("stateAAR.csv")
figure(title=" Age Adjusted Rates by Year",width= 1500, height =600) %>%
ly_segments(year, lci*100000, year, uci*100000, data=aar, color = "#b37700", width = 1) %>%
ly_points(year, adj.rate*100000, glyph = 21, size=6, data = aar, hover= "<strong>Rate per 100,000:</strong> #rateHundThou </br> <strong>Upper Confidence:</strong> #uciHT </br><strong> Lower Confidence:</strong> #lciHT " , color="#666622" )%>%
x_axis(label ='Year')%>%
y_axis(label ='Age Adjusted Rate')
```
Row
You can just add CSS styling directly to your markdown document (no JQuery required):
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
<style>
body {
padding-top:0px
}
.navbar{
visibility: hidden
}
</style>
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
hist(iris$Sepal.Length)
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
hist(iris$Sepal.Width)
```
### Chart C
```{r}
hist(iris$Petal.Length)
```
Results in:
I am not aware of any flexdashboard option. But you could use jQuery to remove the navbar and move the body up. Just include the following snippet right after your YAML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.navbar').remove();
$('body').css('padding-top', '0px');
});
</script>
I think this leaves the main navigation bar of the parent document untouched. If not it might need some lsight modification.

can I produce a figure caption in r markdown with eval=false?

If I have the MWE:
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers",eval=FALSE}
summary(cars)
```
then I do not get a caption. But if I do:
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers"}
summary(cars)
```
i.e. remove eval=FALSE then the caption no longer loads.
why I wish to do this?
I want to put example bits of code into my document. the code won't actually work, hence why I want to supress it. Something like
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers",eval=FALSE}
for (i in 1:length(c){
#do something
}
```
where I am merely demonstrating a for loop, but not actually running the code.
As far as I know, knitr doesn't support captions for code by default. The easiest way to label your code blocks would be to add an explanation below the box in the markdown.
If you must have captions in the r code, you can use chunk hooks. Here's an example for your case:
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
```{r}
library(knitr)
knit_hooks$set(wrapper = function(before, options, envir) {
if (!before) {
sprintf(options$comment)
}
})
```
```{r comment="Figure 1. Some random numbers",wrapper=TRUE,eval=FALSE}
for (i in 1:length(c){
#do something
}
```
We have defined a hook (wrapper), where if we call wrapper=TRUE in any chunk options, the comment argument is printed below.

Resources