4

I am generating an HTML report using Rmarkdown in which I want the user to have an option of looking at code (when they want by using a toggle show/hide code) before each section or figure.

I am wondering if there is an option to do so globally and individually for each code chunk.

I have looked at some previous solutions using javascript, but I am not familiar with the language. I was hoping there is an option I can choose within Rmarkdown.

Previous approaches using javascript are shown here and here, but I am not sure how to include these in my Rmarkdown file. I have tried the following, but it didn't work

<script src="toggleR.js"></script> 
```{r}
summary(cars)
```

A working example in Rmarkdown would be extremely helpful!!

Thanks

Community
  • 1
  • 1
Satya
  • 1,708
  • 1
  • 15
  • 39
  • The accepted answer for your second link should give you what you want. For output chunks take a look at this: http://stackoverflow.com/questions/37755037/toggle-visibility-of-fold-output-chunks-in-rmarkdown-html-documents/37839683#37839683 – Martin Schmelzer Jun 16 '16 at 07:41
  • Possible duplicate of [How to hide code in RMarkdown, with option to see it](http://stackoverflow.com/questions/14127321/how-to-hide-code-in-rmarkdown-with-option-to-see-it) – Martin Schmelzer Jun 16 '16 at 14:12

1 Answers1

4

From the answer to a similar question by Yihue -this functionality has now been added as code folding. See more at http://rmarkdown.rstudio.com/html_document_format.html

Satya
  • 1,708
  • 1
  • 15
  • 39