-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.R
62 lines (47 loc) · 1.35 KB
/
main.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
58
59
# R Report POC
library(plumber)
# Setup -----------------------------------------------------------------------
if(!fs::dir_exists("static")) {
fs::dir_create("static")
}
rmarkdown::render(
input = "index.Rmd",
output_file = "static/index.html",
clean = TRUE
)
# This makes the rendered index file available at the base url
#* @assets ./static /
list()
# Shared Functions ------------------------------------------------------------
render_Rmd <- function(fn, ext, args) {
tmp <- fs::file_temp(ext = ext)
rmarkdown::render(
input = paste0("reports/", fn, ".Rmd"),
output_file = tmp,
clean = TRUE,
params = args,
)
readBin(tmp, "raw", n = fs::file_info(tmp)$size)
}
# Reports ---------------------------------------------------------------------
# rnorm plot in pdf
#* @serializer contentType list(type="application/pdf")
#* @get /rnorm/<n:int>
function(n){
n <- min(n, 10e5)
render_Rmd("rnorm", ".pdf", list(n = n))
}
# Swiss Public Transport Time Table
#* @serializer contentType list(type="application/pdf")
#* @get /swiss-public-transport-timetable/<from>/<to>
function(from, to){
args <- list(from = from, to = to)
render_Rmd("swiss-public-transport-timetable", ".pdf", args)
}
# Plotly Plot
#* @get /plotly/<species>
#* @html
function(species){
args <- list(species = species)
render_Rmd("plotly", ".html", args)
}