4

I am trying to create an rmd html document which uses code folding as well as shiny embedding. I have tried to do this using the default shiny rmd doc but adding in code_folding: hide:

---
title: "Untitled"
author: "Author"
date: "3/29/2019"
output: 
  html_document: 
    code_folding: hide
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Inputs and Outputs

You can embed Shiny inputs and outputs in your document. Outputs are automatically updated whenever inputs change.  This demonstrates how a standard R plot can be made interactive by wrapping it in the Shiny `renderPlot` function. The `selectInput` and `sliderInput` functions create the input widgets used to drive the plot.

```{r eruptions}
inputPanel(
  selectInput("n_breaks", label = "Number of bins:",
              choices = c(10, 20, 35, 50), selected = 20),

  sliderInput("bw_adjust", label = "Bandwidth adjustment:",
              min = 0.2, max = 2, value = 1, step = 0.2)
)

renderPlot({
  hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
       xlab = "Duration (minutes)", main = "Geyser eruption duration")

  dens <- density(faithful$eruptions, adjust = input$bw_adjust)
  lines(dens, col = "blue")
})
```

Which gives:

enter image description here

So as you can see, the code is not folded/hidden. I have successfully implemented each of these individually, but how can they both be used in the same document? I think they clash somehow - does anyone know of a workaround?

Thanks!

KGee
  • 771
  • 7
  • 26

0 Answers0