generated from edgi-govdata-archiving/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_parameterized.R
58 lines (42 loc) · 1.62 KB
/
run_parameterized.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library(pagedown)
library(here)
library(purrr)
library(dplyr)
load("names.rda")
names <- cd2
rm(cd2)
param_table <- names %>%
rename(
region = Region,
cd_state = Identity,
state = State,
district = District
) %>% select(cd_state,state,district,full_name)
target <- c("ND00")
#so for shiny we would want the target to be specific2
selected <- param_table %>% filter(param_table$cd_state %in% target)
render_report <- function(region = selected$region,
cd_state = selected$cd_state,
full_name = selected$full_name,
state = selected$state,
district = selected$district) {
template <- "CD_template_2024.rmd"
out_file <- paste0(cd_state, "_2023")
parameters <- list(cd_state = cd_state,
full_name=full_name,
state=state,
district=district)
pagedown::chrome_print(rmarkdown::render(template, params = parameters,
envir = new.env(),clean = TRUE, output_dir = ("Output"), output_file = out_file,
))
htmls <- dir(path="Output", pattern=".html")
invisible(file.remove(file.path("Output", htmls))) #delete only the html files
#remove the invisible() command on the line above if you would like to see in the console files are removed
# invisible(TRUE)
}
#use this function if you just want to run one report
# render_report()
# render_report(cd_state = selected$cd_state, full_name = selected$full_name, state = selected$state)
#use these two if you want to run multiple reports
params_list <- as.list(selected)
pmap(params_list, render_report)