-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.R
58 lines (49 loc) · 2.51 KB
/
report.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
"Report which can be exported from the tool"
warning_text = reactive({
if(input$global_emission_budget_gt_2020 > 680 & input$max_negative_emissions_perc > 0) {
"<b>Warning</b>:<br />You have combined a relatively large global budget with possible<br />
net negative emissions. Please note that the resulting emission<br />
overshoot increases the risk of exceeding climate tipping points."
} else if(input$global_emission_budget_gt_2020 >= 800 & input$max_negative_emissions_perc == 0) {
"<b>Warning</b>:<br />You have chosen a relatively high global budget. Please note the<br />
higher risk that tipping points in the climate system can be exceeded."
} else {
""
}
})
output$report <- downloadHandler(
filename = "espm_report.pdf",
content = function(file) {
# Select template for report depending on selected file type
template_file <- "report_pdf.Rmd"
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path(tempdir(), "report.Rmd")
tempReport2 <- file.path(tempdir(), "style.css")
file.copy(paste0("www/", template_file), tempReport, overwrite = TRUE)
file.copy("www/style.css", tempReport2, overwrite = TRUE)
# Set up parameters to pass to Rmd document
params <- list(first_year = FIRST_YEAR,
result = result(),
date_display_range = date_display_range(),
overshoot_amounts = overshoot_amounts(),
colors_to_display = colors_to_display(),
eu_emissions_1990 = EU_EMISSIONS_1990,
threshold_linear_rm1 = THRESHOLD_LINEAR_RM1,
global_emission_budget_gt = global_emission_budget_gt(),
pop_weighting = input$pop_weighting,
global_emission_budget_gt_2020 = input$global_emission_budget_gt_2020,
eu_emission_budget_gt = eu_emission_budget_gt(),
max_negative_emissions_gt = max_negative_emissions_gt()*-1,
warning_text = warning_text()
)
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)