-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_outputs.R
46 lines (40 loc) · 1.65 KB
/
create_outputs.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
################################################################################
# To build the dashboard, open this file in RStudio, and click the 'Source'
# button (this will run all of the code below). Once it has finished running,
# the complete dashboard can be found in the 'output' folder as an HTML file
# and a ZIP file.
################################################################################
html_output_name <- "Example Dashboard"
code_output_name <- "Example Dashboard - R source code"
# Create output directories if they don't exist
if(!dir.exists("output/data")) {
dir.create("output/data", recursive = TRUE)
}
if(!dir.exists("output/results")) {
dir.create("output/results", recursive = TRUE)
}
# Import and clean the raw data
source("scripts/01_clean_data/flights.R", local=new.env())
# Generate summary data for the dashboard pages
source("scripts/02_calculate_summary_data/daily_totals.R", local=new.env())
source("scripts/02_calculate_summary_data/fancy_top_destinations.R", local=new.env())
source("scripts/02_calculate_summary_data/top_destinations.R", local=new.env())
# Render the dashboard to HTML
rmarkdown::render(
here::here("dashboard.Rmd"),
output_dir = "output",
output_file = glue::glue("{html_output_name}.html"),
envir = new.env()
)
# Create a ZIP archive with the HTML dashboard
zip::zipr(
zipfile = glue::glue("output/{html_output_name}.zip"),
files = glue::glue("output/{html_output_name}.html")
)
# Create a ZIP archive with the source code
files <- list.files()
files <- files[!grepl("^output$", files)] # Don't include output folder
zip::zipr(
zipfile = glue::glue("output/{code_output_name}.zip"),
files = files
)