Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using plumber package in Rscript and running script from cmd

In my Rscript (run.R):

library(plumber)
r <- plumb("script.R")
r$run(host="127.0.0.1",port=8000)

If I run the above code using RStudio or R console it works fine and gives me access after following output:

Starting server to listen on port 8000 Running the swagger UI at http://127.0.0.1:8000/swagger/

but when I try to run the same code as a .R file using Rscript, R CMD BATCH,R < run.R, pm2 it gets stuck at;

Starting server to listen on port 8000

and on accessing address I get 404: Resource Not Found Error. Also, note that I want to run this on windows therefore didn't try littler. Any idea, what I am doing wrong here. Thanks!

like image 278
Yusra Shahid Avatar asked Jan 01 '18 08:01

Yusra Shahid


1 Answers

run takes a swagger argument that defaults to interactive(). i.e. it only enables swagger if you're running interactively.

You can hardcode this to TRUE if you want Swagger to be enabled on your router even when run programmatically.

r$run(host="127.0.0.1", port=8000, swagger=TRUE)
like image 169
Jeff Allen Avatar answered Sep 18 '22 20:09

Jeff Allen