0

In an R notebook, is it possible to make a graph discoverable? I would like the graph to be revealed only when a user wants to see it.

Imagine a situation where some readers may want to see a level of detail that I don't want to show by default, because I expect it to be distracting or confusing for most readers.

The best I've been able to come up with is to use tabs and have the default tab be empty. But it feels like a bit of a hack. Are there other ways to implement discoverability?

hide tab

show tab

---
output: html_document
---

```{r setup, include = FALSE, message = FALSE, echo = FALSE}
library(tidyverse)
knitr::opts_chunk$set(echo = FALSE,
                      message = FALSE,
                      tidy = TRUE,
                      warning = FALSE
)
```

### Mileage

The average mpg for the cars in this dataset is `r round(mean(mpg$hwy), 1)`.

#### Distribution of the data  {.tabset .tabset-fade .tabset-tabs}

##### Hide

##### Show

```{r}
qplot(mpg$hwy, bins = 20)
```
user2363777
  • 947
  • 8
  • 18
  • 2
    Have you tried the answers here? https://stackoverflow.com/questions/42630248/collapsing-hiding-figures-in-r-markdown – joshpk Jun 17 '19 at 20:35
  • 2
    Also see this answer that using the `details` element: https://stackoverflow.com/questions/42543431/code-folding-for-individual-chunks-in-r-markdown/53870441#53870441 – aosmith Jun 17 '19 at 20:39
  • I quite like the solution using the `details` element. I tried to improve discoverability of that element by adding some CSS that turns the pointer into a pointing hand when the user mouses over the element: `` – user2363777 Jun 18 '19 at 22:07

0 Answers0