Created
March 5, 2020 21:12
-
-
Save robkooper/163f6e8542e94c835a9abff9770354bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plumber) | |
# create the actual app | |
master_pr <- plumber$new() | |
# list of all files with endpoints, suggest to keep one file per level | |
# each file needs a unique endpoint | |
f1_pr <- plumber$new("plumber1.R") | |
master_pr$mount("/f1", f1_pr) | |
f2_pr <- plumber$new("plumber2.R") | |
master_pr$mount("/f2", f2_pr) | |
# start the app | |
master_pr$run(port=8000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# plumber.R | |
#* Echo back the input | |
#* @param msg The message to echo | |
#* @get /echo | |
function(msg=""){ | |
list(msg = paste0("The message is: '", msg, "'")) | |
} | |
#* Plot a histogram | |
#* @png | |
#* @get /plot | |
function(){ | |
rand <- rnorm(100) | |
hist(rand) | |
} | |
#* Return the sum of two numbers | |
#* @param a The first number to add | |
#* @param b The second number to add | |
#* @post /sum | |
function(a, b){ | |
as.numeric(a) + as.numeric(b) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# plumber.R | |
#* Echo back the input | |
#* @param msg The message to echo | |
#* @get /echo | |
function(msg=""){ | |
list(msg = paste0("The message is: '", msg, "'")) | |
} | |
#* Plot a histogram | |
#* @png | |
#* @get /plot | |
function(){ | |
rand <- rnorm(100) | |
hist(rand) | |
} | |
#* Return the sum of two numbers | |
#* @param a The first number to add | |
#* @param b The second number to add | |
#* @post /sum | |
function(a, b){ | |
as.numeric(a) + as.numeric(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment