R Generate slides in a slide presentation in a loop

I want to create N slides to send descriptive statistics for N subsets of (large) data using the slidify package. In the previous discussion, Create parametric documentation R markdown? a combination of brew and knitr was recommended.

I am wondering if slidify its workaround for such a task? I assume that repeating the data to fill the slides is even more logical than for plain text ...

Minimal example (from the above question I need slides instead of paragraphs)

 ```{r loopResults, echo=FALSE, results='asis'} results = list(result1 = data.frame(x=rnorm(3), y=rnorm(3)), result2=data.frame(x=rnorm(3), y=rnorm(3))) for(res in names(results)) { cat(paste("<h3>Results for: ", res, "</h3>>")) plot(results[[res]]$x, results[[res]]$y) } 
+6
source share
1 answer

For those who are interested, this is what I have today (for the loop + the location of two columns ( 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) } ``` 
+8
source

Source: https://habr.com/ru/post/955507/


All Articles