Search code examples
rslideshowioslides

How to make slide deck in R based on a list?


I have some moderate experience in R. I'm trying to make flashcard slides for remote learning. I need to display the slides on my screen for my student to read, and flip through them quickly.

I have a list of about 4,000 words, broken down into different categories. I want to be able to filter on the category, and build a slide deck that has one word on each slide.

The pie-in-the-sky goal would be a Shiny app, with a drop-down to select category, then a check-box selection to select which words to include in the slide deck, then produce an html slide deck.

Below is a sample of the word list I'm using:

Word Category | word | index


Short a CVC | ban | 1

Short a CVC | bat | 1

Short a CVC | can | 1


Solution

  • I'd suggest for a first pass you should make an R Markdown document with Slidy or some other HTML presentation format output. Just include one or two slides in it, and play with it until the format looks right.

    Then write an R function that outputs the header and as many slides as required to a file, then calls rmarkdown::render() on that file. Your R function can take as input all the characteristics like Category that you will eventually put in the Slidy app.

    To get you started, here's a two-slide Slidy presentation:

    ---
    output: slidy_presentation
    ---
    ##
    
    <div style="font-size:300%;position:absolute;top:50%;left:50%;transform: translate(-50%,-50%)">
    ban
    </div>
    ##
    
    <div style="font-size:300%;position:absolute;top:50%;left:50%;transform: translate(-50%,-50%)">
    bat
    </div>
    

    The first 3 lines are the header; after that, slides start with the ## marker. See the Slidy documentation if you want to customize it.

    Once you have this working from your R function, you can write a Shiny app that offers choices in menus then calls that function.

    Edited to add: for various reasons, it turns out that xaringan isn't well suited to this, so I've switched everything to Slidy. The function below uses Slidy.

    makeSlideDeck <- function(words, outfile = "slides.html") {
      header <- '---
    output: slidy_presentation
    ---'
      slide <- '##
    
    <div style="font-size:300%;position:absolute;top:50%;left:50%;transform: translate(-50%,-50%)">
    WORD
    </div>'
    
      lines <- character(length(words) + 1)
      lines[1] <- header
      for (i in seq_along(words))
        lines[i + 1] <- sub("WORD", words[i], slide, fixed = TRUE)
      filename <- paste0(tools::file_path_sans_ext(outfile), ".Rmd")
      writeLines(lines, filename)
      rmarkdown::render(filename)
    }
    

    Run it like this:

    dat <- c("ban","bat","can")
    makeSlideDeck(dat)
    

    It will produce slides.Rmd and process that into slides.html, which will contain your slides.