For those interested, this is what I have by far (for-loop + two column layout (as here)))
---
title: Loop test
widgets: [bootstrap, quiz]
---
## Simplest Example##
```{r echo = F, fig.width = 12, fig.height = 7, results='asis'}
library(data.table)
data <- as.data.table(list(days = 1:100, revenue = runif(10, 1, 100), profit = runif(10, 1, 10), department = factor(sample(letters[1:3]))))
for(j in levels(data$department)) {
dataj <- data[data$department == j,]
cat("\n\n--- &twocol\n")
cat(paste("\n\n## Department: ", j, "##\n") )
cat("\n*** left\n")
cat(paste("\nMean profit = ", round(mean(dataj$profit)), "\n"))
cat(paste("\nMean revenue = ", round(min(dataj$revenue))), "\n")
cat("\n*** right\n\n")
z<-ggplot(data = dataj ) +
geom_density(aes(x = profit), alpha = 0.3) +
geom_density(aes(x = revenue), alpha = 0.3)
print(z)
}
```