Using Flexdashboard, I want to put some text and a plot inside a loop - it should loop through variables, and I don't know how many there will be. But the plots appear side by side, not down the page, and the text is lost.
Example:
---
title: "Cars Test"
output: flexdashboard::flex_dashboard
---
```{r}
library(ggplot2)
data(cars)
for(var in names(cars)) {
htmltools::tags$p(var)
print(ggplot(cars, aes_string(var)) +
geom_histogram())
}
```
Gives me:
If I don't loop, and instead just run the code for each variable:
---
title: "Cars Test"
output: flexdashboard::flex_dashboard
---
```{r}
library(ggplot2)
data(cars)
var <- "speed"
htmltools::tags$p(var)
print(ggplot(cars, aes_string(var)) +
geom_histogram())
var <- "dist"
htmltools::tags$p(var)
print(ggplot(cars, aes_string(var)) +
geom_histogram())
```
I get what I expect:
Which is what I expect.
is there a way to get (something like) the second page, using the first code.