Multiple chunks in a tab - r

I want chunks of Example1 and Example2 in a single tab and Example3 in another tab. The code below is showing everything in one tab. In my desired output, some chunks in sectionA tab and some in sectionB tab.
---
title: "R Notebook"
output:
html_document:
df_print: paged
code_folding: show
theme: united
highlight: tango
toc: true
toc_float: true
toc_depth: 3 # upto three depths of headings (specified by #, ## and ###)
---
```{r, echo=FALSE}
library(rmarkdown) #used for syntax highlighting in this document
```
## Sections {.tabset}
### Section A
# Example1
```{r, eval=FALSE}
plot(cars)
```
<details>
<summary>Click for Output</summary>
```{r, echo=FALSE, eval=TRUE}
plot(cars)
```
</details>
### Section B
# Example2
```{r}
quantile(mtcars$mpg, probs = c(0.99))
```
## {-}
# Example3
```{r table}
knitr::kable(mtcars[1:5,, 1:5], caption = "A table caption")
``````

If I understand correctly, you want something along these lines? Once you start a tabbed section, you can't willy-nilly throw around subsections but should follow specific hierarchy. If you have a tabbed section of level ##, everything under level ### will become a tab. Anything deeper than that will become a title in the said tab.
## Sections {.tabset}
### Section A
#### Example1
```{r, eval=FALSE}
plot(cars)
```
<details>
<summary>Click for Output</summary>
```{r, echo=FALSE, eval=TRUE}
plot(cars)
```
</details>
#### Example2
```{r}
quantile(mtcars$mpg, probs = c(0.99))
```
### Section B
#### Example3
```{r table}
knitr::kable(mtcars[1:5,, 1:5], caption = "A table caption")
``````

Related

About the hyperlink in RMARKDOWN

In rmarkdown, we can create a catalog using 'toc: yes',using the hyperlink, i can link to subtitle.
Now, i want to link subtitle to catalog ? (in the final html, i with to click subtitle,then back to top of the file)
---
title:'my markdown file'
output:
html_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## subtitle 1 :R Markdown
```{r cars}
summary(cars)
```
## subtitle 2:Including Plots
```{r pressure, echo=FALSE}
plot(pressure)
```
You may enclose subheader in an HTML tag <a>.
---
title: 'my markdown file'
output:
html_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## subtitle 1 :R Markdown
```{r cars}
summary(cars)
as.matrix(rnorm(100))
```
## subtitle 2:Including Plots
```{r pressure, echo=FALSE}
plot(pressure)
```

Cross references between slides and its content

In an R markdown presentation with output format beamer (to generate a LaTex/PDF file), is it possible to create cross-references between slides, i.e. pages of the final PDF?
This would be very helpful to quickly jump between slides, e.g. to navigate to an appendix at the end of the presentation.
I tried to use bookdown commands as proposed in this SO post, but without success.
MWE:
---
title: "Cross references between slides"
output:
# beamer_presentation: default
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Bullets with references
- Bullet 1: \ref{tab:my-table}
- Bullet 2: \ref{fig:my-plot}
- Bullet 3: \ref{appendix}
## Bullets with references (bookdown)
- Bullet 1: \#ref(tab:my-table)
- Bullet 2: \#ref(fig:my-plot)
- Bullet 3: \#ref(appendix)
## table
```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```
## plot
```{r my-plot, pressure}
plot(pressure)
```
## appendix
my appendix
For linking to the appendix, you can use
- Bullet 3: \hyperlinkappendixstart{appendix}
If you examine the tex code produced by your MWE you will see that your table and figure are both included without caption or figure/table environment, but you can reference the slide they are on
- Bullet 1: \hyperlink{table}{table}
- Bullet 2: \hyperlink{plot}{plot}
MWE:
---
title: "Cross references between slides"
output:
beamer_presentation:
theme: "default"
keep_tex: true
includes:
in_header: preamble.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Bullets with references
- Bullet 1: \hyperlink{table}{table}
- Bullet 2: \hyperlink{plot}{plot}
- Bullet 3: \hyperlinkappendixstart{appendix}
## table
```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```
## plot
```{r my-plot, pressure}
plot(pressure)
```
## appendix
\appendix
my appendix
Approach 2
or you could use the caption package to add captions to your tables and plots
---
title: "Cross references between slides"
output:
beamer_presentation:
theme: "default"
keep_tex: true
includes:
in_header: preamble.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Bullets with references
- Bullet 1: \ref{foo}
- Bullet 2: \ref{bar}
- Bullet 3: \hyperlinkappendixstart{appendix}
## table
```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```
\captionof{table}{foo}
\label{foo}
## plot
```{r my-plot, pressure}
plot(pressure)
```
\captionof{figure}{bar}
\label{bar}
## appendix
\appendix
my appendix
using this as preamble.tex:
\setbeamertemplate{caption}[numbered]
\usepackage{caption}

Include table of contents in flexdashboard

I would like to include a table of contents in my flexdashboard document.
Exactly like the table of contents we can see in the documentation : http://rmarkdown.rstudio.com/flexdashboard/using.html
I have tried to add toc:true as in a classical RMarkdown document but it does not seem to work.
---
title: "Reporting"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
toc: true
---
# Page1
Row
-----------------------------------------------------------------------
## chap1
### chart 1
```{r cars1, echo=FALSE}
plot(pressure)
```
### chart 2
```{r cars2, echo=FALSE}
plot(pressure)
```
Row
-----------------------------------------------------------------------
## chap2
### chart 3
```{r pressure, echo=FALSE}
plot(pressure)
```
# Page 2
Row
-----------------------------------------------------------------------
### p2 chap 1
```{r test}
plot(pressure)
```
Row
-----------------------------------------------------------------------
### p2 graph2
```{r test2, echo=FALSE}
plot(pressure)
```
In this example, I would like to see in Page 1 a table of contents containing two lines : chap1 and chap2. In Page 2 I don't need a table of contents.
How can I do that ?
Thank you.

hiding entire pages in an r markdown document

I have the r markdown document below. I would like to hide page 2 if parameter "P" is not equal to A.
So the result would be if parameter P != A then only 3 pages are produced.
Is this possible somehow?
---
title: "Untitled"
output:
pdf_document:
toc: yes
params:
P: A
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\newpage
## PAGE2
this is text for page 2
this is text for page 2
```{r cars}
summary(cars)
```
\newpage
## PAGE3
this is text for page 3
```{r pressure, echo=FALSE}
plot(pressure)
```
\newpage
## PAGE4
this is text for page 4
You could comment the section out based on P value. Here is a bit of a hackish way to do it: surround the section with \iffalse/\fi. Note that the R code inside the section still needs to be valid for this to work (it will be compiled by knitr, but ignored by latex).
```{r, echo=FALSE, results='asis'}
if(params$P != "A")
cat("\\iffalse")
```
## PAGE2
this is text for page 2
this is text for page 2
```{r cars}
summary(cars)
```
\newpage
```{r, echo=FALSE, results='asis'}
if(params$P != "A")
cat("\\fi")
```

Show code in flexdashboard

I'm trying to produce a flexdashboard with R and want to show code in my presentation, but this seems not to work.
Here a little example:
---
title: "Test"
output:
flexdashboard::flex_dashboard
---
```{r setup, include=FALSE}
library(flexdashboard)
```
### Code
```{r, eval=FALSE, include=TRUE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
### Output
```{r, fig.align='center', echo = FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
Even other chuck options like fig.show = 'hide' will not work.
Is it possible to show code in a R-chuck in flexdashboard?
The code highlights would be a benefit instead of a plain text.
If you want both the code and plot to show set the chunk options to: echo = true
If you just want code set it to: echo=TRUE, eval=FALSE
---
title: "Test"
output:
flexdashboard::flex_dashboard
---
```{r setup, include=FALSE}
library(flexdashboard)
```
### Code
```{r, echo=TRUE, eval=FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
### Code and Plot
```{r, echo=TRUE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
### Plot
```{r, fig.align='center', echo = FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
It won't show as a panel in your presentation, but to add a </> Source Code button to your dashboard, include source_code: embed in your YAML.
---
title: "Example"
output:
flexdashboard::flex_dashboard:
source_code: embed
---

Resources