10

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.

Aradhya Kasat
  • 221
  • 1
  • 11
  • See also [this answer](https://stackoverflow.com/questions/44469026/sequence-of-execution-for-closures/44470288#44470288) which tries to explain a similar problem – Uwe Jun 12 '17 at 09:29

1 Answers1

9

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

Aradhya Kasat
  • 221
  • 1
  • 11