RMarkdown presentation sourcing from dataframe?

40 views Asked by At

I'm trying to make a presentation with RMarkdown instead of powerpoint, because I'd like to illustrate something where the layout is repeated on every slide, but the actual content may change. Specifically, I'd like to display two pictures on the screen, and 4 words below corresponding to each picture. The filename and the words are defined in a dataframe, and each slide takes information from the next row. However, I'm not able to understand how to implement any of this in markdown. I only have experience creating markdown files which display the results of my analyses, and it appears that making a presentation is a completely different skill. With the help of chatgpt, I have written the following code (for now just with one word)

---
title: "Stimuli"
output:
  xaringan::moon_reader

---
{r setup, include=FALSE}
#remotes::install_github('yihui/xaringan')

library(xaringan)
#knitr::opts_chunk$set(echo = FALSE)
stim <- read.csv("stimuli list.csv")

for (i in seq_len(nrow(stim))) {
  cat("\n---\n")
  cat("## Slide ", i, "\n\n")
  
  cat("![Picture 1](", stim$image.name1[i], ")\n")
  
  cat("![Picture 2](", stim$image.name2[i], ")\n\n")
  

  cat("- ", stim$word1[i], "\n")
}

But all I'm getting is the code displayed on the screen of one slide. Alternatively, I've also tried:

---
title: "Stimuli"
output: ioslides_presentation
---

{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = FALSE)
{r,
Copy code
# Load the required libraries
library(knitr)

# Loop through each pair of rows in the dataframe
for (i in seq(1, nrow(stim), by = 2)) {
  cat("\n---\n")
  cat("# Slide ", i, "/", i + 1, "\n\n")
  
  # Display pictures side by side
  cat("![Left Picture ", i, "](", stim$Picture[i], "){width=45%}\n")
  cat("![Right Picture ", i + 1, "](", stim$Picture[i + 1], "){width=45%}\n\n")
  
  # Display the words as bullet points
  cat("- ", paste(stim$Words[i], collapse = "\n- "), "\n")
  cat("\n- ", paste(stim$Words[i + 1], collapse = "\n- "), "\n")
}

And this was probably the closest because it gave me multiple slides, but each slide was different and only one of them showed a picture ( or half of it, the other half was outside the slide)

Is it actually possible to create a presentation this way? I couldn't find any examples so any tips would be appreciated

0

There are 0 answers