-
Notifications
You must be signed in to change notification settings - Fork 2
/
01-plumber.R
55 lines (50 loc) · 860 Bytes
/
01-plumber.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
library(ggplot2)
#* Echo my name
#*
#* @get /whoami
function() {
return(
list(name = "Daniel")
)
}
#* Echo back the input
#*
#* @param msg The message to echo
#* @get /echo
function(msg = "") {
return(
list(msg = paste0("Message: '", msg, "'"))
#list(msg = glue::glue("Message: '{msg}'"))
)
}
#* Takes the average between 2 numbers
#*
#* @param x the first number
#* @param y the sectond number
#* @get /avg2
function(x, y) {
x <- as.numeric(x)
y <- as.numeric(y)
return(
list(result = (x + y) / 2)
)
}
#* Plots cars dataset
#*
#* @get /carplot
#* @png
function() {
print(
ggplot(cars, aes(x = speed, y = dist)) + geom_point()
)
}
#* Generate an error
#*
#* @get /err
function(res) {
msg <- "Hi! you did something wrong :)"
res$status <- 400 # bad request
return(
list(error = jsonlite::unbox(msg))
)
}