Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we return ggplot graphs through plumber web api? [duplicate]

I was plotting a bar plot using ggplot and I created this function as a web api using plumber package in R.

 library(plumber)
 library(ggplot2)
#' @get /histogram_test
#' @png
  histogram_test <- function(){
  mtcars=mtcars
  b=ggplot(mtcars,aes(mtcars$cyl))
  b+geom_bar()
}

Then I run:

r <- plumb("plum_api.R")
r$run(port=8000)

But this does not return the plot on the browser.

like image 516
Aradhya Kasat Avatar asked Jun 12 '17 08:06

Aradhya Kasat


1 Answers

So it works if in the last line we just use the print command as: print(b+geom_bar()).

like image 66
Aradhya Kasat Avatar answered Oct 23 '22 02:10

Aradhya Kasat