Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapsing / hiding figures in R markdown

Tags:

r

r-markdown

In my rmarkdown document, I am able to show and hide code with the following - which creates a convenient button on the righthand side of the document before each block of code:

output: 
  html_document:
    code_folding: hide

enter image description here enter image description here

Is there a similarly convenient method to hide tables or figures? If so, please provide a reference as I have not been able to find any. Otherwise a workaround would be appreciated, thank you!

like image 486
the_darkside Avatar asked Mar 06 '17 16:03

the_darkside


1 Answers

I have not been able to get the above solution (or others I found) to work consistently, but using the in-line html (Bootstrap example/solution) I found at W3schools.com works well in Rmarkdown.

I use it to show a simple plot in html output in the example below. It should work with any chunk output:

<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName"> Show/Hide </button>  
<div id="BlockName" class="collapse">  

```{r}
plot(mtcars$disp, mtcars$mpg)
```

</div>

note: If you use this on multiple sections, each one needs a unique id (ie replace BlockName with a unique id for each section to be collapsed.)

like image 166
Matt L. Avatar answered Oct 04 '22 22:10

Matt L.