R API for Internet Access

Hi I have R code which I converted to API using plumber package .

library(plumber)
r <- plumb("code.R")
r$run(port=8000)

      

The code is in a file code.R

and using the lines above I can access the API from my local machine with the URL http: // localhost: 8000 / functionname

However, when I replace localhost with my IP address and access it from other computers on the network, I cannot access the API. Why is this?

+3


source to share


2 answers


to make the kernel work on my machine.

r$run(host = "0.0.0.0",port=8000)

      



and then to access it just

your_ip:8000/functionname

      

+1


source


By default, plumber listens on host 0.0.0.0, which means it should listen on all devices, be it your IP or localhost. It looks like your computer has a firewall, or your organization might have a firewall in front of the machine in use. You also need to confirm that the IP is being routed (for example, you are not trying to access 192.168 .. from another local network).



I would dissuade you from trying to host the API on your personal machine or on the server where you are doing iterative development, as this requires opening a firewall and accepting traffic on a more sensitive server. The best practice here would be to deploy your API to a server that is dedicated to receiving public traffic. Here's one easy way to get this setup now built into the plumber's development version: https://plumber.trestletech.com/docs/digitalocean/

0


source







All Articles