Slide 40
Slide 40 text
Plumber - Getting Started
plumber.R
#' Plot out data from the iris dataset
#' @param spec If provided, filter the data to only this species (e.g. 'setosa')
#' @get /plot
#' @serializer png
function(spec){
my_data <- iris
title <- "All Species"
# Filter if the species was specified
if (!missing(spec)){
title <- paste0("Only the '", spec, "' Species")
my_data <- subset(iris, Species == spec)
}
plot(my_data$Sepal.Length, my_data$Petal.Length,
main=title, xlab="Sepal Length", ylab="Petal Length")
}
©leoluyi, 2021 40