tests/outpptx/generate_ppt.R

# source("preproc.r", encoding = "UTF-8")
library(officer)
library(tidyverse)

add_logo_page_explain_page <- function(presentation_template){
  cat("in add_logo_page_explain_page \n")
  d1 <- "servey for. when"
  d2 <- "n people, revach" 
  d3 <- "how we got the data"
  
  presentation_template %>% 
    add_slide(layout = "face", master = "master_face") %>% 
    ph_with(value ="results of survey X", location = ph_location_label("title")) %>% 
    
    add_slide(layout = "bg", master = "master_content") %>% 
    ph_with(value ="רקע", location = ph_location_label("title")) %>% 
    ph_with(value =d1,location = ph_location_label("desc1")) %>%
    ph_with(value =d2,location = ph_location_label("desc2")) %>%
    ph_with(value =d3,location = ph_location_label("desc3")) %>%
    add_slide(layout = "content_slide", master = "master_content_eng") %>%
    ph_with(value ="רקע", location = ph_location_label("title")) %>%
    ph_with(value ="",location = ph_location_label("content"))
  
  
}

add_plot <- function(presentation_template){
  
  cat("in add_plot \n")
  
  presentation_template %>% 
    add_slide(layout = "content_slide", master = "master_content") %>% 
    ph_with(value ="mytitle", location = ph_location_label("title")) %>% 
    ph_with(value ="ggplot", location = ph_location_label("content"))
  
  
}

####################
# create the presentation ----
create_presentation <- function(filename = paste0("c:/temp/", str_replace_all(Sys.time(), ":", "_"), "-tmp_presentation.pptx")){
  
  cat("Starting to build presentation \n")
  
  ready_presentation <- read_pptx("tests/outpptx/Template.pptx") %>%
    add_logo_page_explain_page() %>% 
    add_slide_plot(slide_ID = "qqq",myplot = "empty",description_text = "ddd") %>% 
    add_plot()
  
  cat("adding page numbers \n")
  
  n_slides <- length(ready_presentation)
  for (i_slide in 2:n_slides) {
    ready_presentation <- ready_presentation %>%
      on_slide(index = i_slide) %>%
      ph_with(value = i_slide, location = ph_location_type('sldNum'))
  }
  
  
  print(ready_presentation, target = filename)
  cat("Finished \n")
}





# Actual report ----
create_presentation("tests/presentation.pptx")
sarid-ins/saridr documentation built on Nov. 10, 2020, 9:07 p.m.