1

I have created an Rmarkdown file in a Kaggle Kernel and I am trying to do the following:

1) Set some code chunks as hidden but with a button next to them to allow the viewer to hide or display the code

2) Set some other codes chunks as not hidden with again a buttopn next to them to allow the viewer to hide or display the code

From what I could see in previous questions a suggested solution is

---
title: "test"
output: 
  html_document:
    code_folding: hide
---

That unfortunately is not working for me. I have also set the following in the start of my script

```{r setup, include=FALSE, echo=FALSE}

knitr::opts_chunk$set(echo= TRUE)

and before each code I have the following:

```{r, message = FALSE, warning=FALSE  }
# Load packages
library("ggplot2")
library("pastecs")
library("dplyr")
library("corrplot")

So my question would be, what should I do to get 1) and 2)?

Thanks in advance.

ALEX.VAMVAS
  • 87
  • 1
  • 10
  • 4
    The `code_folding: hide` option should work. I'm not quite sure what a Kaggle Kernel is though, if the RMarkdown file displays on Kaggle's website they may not allow the javascript that's required to do the code folding? – Marius Jul 02 '19 at 00:05
  • @ Marius An example of a Kaggle Kernel is https://www.kaggle.com/hiteshp/head-start-for-data-scientist. Well I am using code_folding: hide but it is not working : )) That is why I thought that maybe I am messing it with the other chunks of code – ALEX.VAMVAS Jul 02 '19 at 00:10
  • My kernel - you can see the code on the bottom is: https://www.kaggle.com/vamvas/replicating-disaster-on-the-titanic – ALEX.VAMVAS Jul 02 '19 at 00:28
  • 3
    Ah, just looked at your kernel and it looks like `code_folding` is not indented enough. It should be indented to the same level as `highlight` etc., it's a sub-option under `html_document`. – Marius Jul 02 '19 at 00:30
  • Thanks Marius, that worked like a charm – ALEX.VAMVAS Jul 02 '19 at 18:04
  • As a follow up is there a way to show specific chunks of code only? So set the option as above that will hide all code and then manually make certain code chunks to appear. – ALEX.VAMVAS Jul 04 '19 at 02:47
  • There are some related questions, e.g. https://stackoverflow.com/questions/37755037/how-to-add-code-folding-to-output-chunks-in-rmarkdown-html-documents, but I don't think there's a particularly easy way. – Marius Jul 04 '19 at 02:53

0 Answers0