How to Deploy Plumber using R studio community edition

I have created two files ,one is plumber file and second one is file with api end points. My problem is how to deploy the api s in the server ?
I can run the plumber commands like assigning the port and ip through console. But when i tried to do it from command line it was not working.

Appreciate your help.

1 Like

Any chance you can provide some simple examples of the type of code you have in your files and what commands you are executing? This should definitely be possible and fairly straightforward!

Also, this section of the docs is probably helpful:

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

This is stored in a file called server.R. I am trying to start the server from command prompt . I have a community edition of Rstudio server. I want to deploy the code,so that it start serving requests.

Perfect! Presuming that “TSDataUpdate.R” is a legitimate plumber file, you should be set to go. The one factor to keep in mind is where you are calling the script from, as this will depend on the working directory (You should have your command prompt sitting in the same directory as the file). So something like Rscript server.R should do the trick, otherwise, though!

If you want to call the file from other places doing something like Rscript /path/to/server.R, or Rscript C:/path/to/server.R (on Windows), then you should probably look into the here package (which has some helpful examples) or the rprojroot package, which makes the here package possible.

Finally, it might be worth sharing what commands you are entering and what errors / messages you are encountering when running things at the command prompt, as it looks like you have things set to go. All very important factors of a reproducible example (reprex).

Thanks Coles,appreciate your quick turn around..

I have verified both the files are sitting in the same directory and i am using R CMD TSServer.R to invoke the server file which contains -

setwd("E:/TSML/ADUT")
library(plumber)
 r <- plumb("TSDataUpdate.R")  
 #r$run(host="127.0.0.1", port=8000)
 
 r$run(host="127.0.0.1", port=8000)

The TSDataUpdate.R contains the API.

Once i run the R CMD TSServer.R i am getting the following error. Also the same file is also getting opened in the R studio.

[13656:4044:0313/140936:VERBOSE1:crash_service_main.cc(68)] Session start. cmdline is [--reporter-url=https://ticinocrashreporter.azurewebsites.net/crash --application-name=VSCode --v=1]
[13656:4044:0313/140936:VERBOSE1:crash_service.cc(142)] window handle is 00100CF6
[13656:4044:0313/140936:VERBOSE1:crash_service.cc(290)] pipe name is \\.\pipe\VSCode Crash Service
dumps at C:\Users\lui\AppData\Local\Temp\VSCode Crashes
[13656:4044:0313/140936:VERBOSE1:crash_service.cc(294)] checkpoint is C:\Users\lui\AppData\Local\Temp\VSCode Crashes\crash_checkpoint.txt
server is https://ticinocrashreporter.azurewebsites.net/crash
maximum 128 reports/day
reporter is electron-crash-service
[13656:4044:0313/140936:VERBOSE1:crash_service_main.cc(84)] Ready to process crash requests
[13656:17652:0313/140936:VERBOSE1:crash_service.cc(323)] client start. pid = 6112
[13656:17652:0313/140937:VERBOSE1:crash_service.cc(323)] client start. pid = 18408
[20128:4704:0313/140937:VERBOSE1:crash_service_main.cc(68)] Session start. cmdline is [--reporter-url=https://ticinocrashreporter.azurewebsites.net/crash --application-name=VSCode --v=1]
[20128:4704:0313/140937:VERBOSE1:crash_service.cc(142)] window handle is 00120D86
[20128:4704:0313/140937:VERBOSE1:crash_service.cc(290)] pipe name is \\.\pipe\VSCode Crash Service
dumps at C:\Users\lui\AppData\Local\Temp\VSCode Crashes
[20128:4704:0313/140937:VERBOSE1:crash_service.cc(294)] checkpoint is C:\Users\lui\AppData\Local\Temp\VSCode Crashes\crash_checkpoint.txt
server is https://ticinocrashreporter.azurewebsites.net/crash
maximum 128 reports/day
reporter is electron-crash-service
[20128:4704:0313/140937:ERROR:crash_service.cc(301)] could not start dumper

Also when using Rscript TSServer.R i am getting the below error

E:\TSML\ADUT>Rscript TSServer.R
Error in library(plumber) : there is no package called 'plumber'
Execution halted

@snehashis I updated my previous post with links that got pulled out by accident. You might want to read through a few of those, as they will likely be helpful to your understanding. You want to be very careful when using setwd in a script. Specifically, beware as Jenny has a humorous threat for setwd users in the link that I shared.

Generally, you also want to use Rscript instead of R CMD for batch processes. Further, it seems clear that the script is not able to find the plumber package, so you should make sure that it is installed and available to the user / directory where the script is being called.

I would also recommend "building up slowly." Start with interactive R.
Then call server.R directly. Then call it from another script like TSServer.R. This will help you build up to the state that you want, rather than starting at the end game and getting confused by behavior like setwd and package dependencies. This is a good general practice to use for debugging, as well - keep digging down closer to the problem to find out where things are going awry.

2 Likes

Thanks Cole Much appreciated. I was using the Shell from the tools menu of RStudio and that was the issue. When i used the windows command prompt,the server started successfully :slight_smile:

1 Like

Glad to hear things are working well!

A post was merged into an existing topic: How to Deploy Plumber