I am pretty new with R. What I am trying to do is to be able to load a URL from another application (Java) which will run an R script and output a JSON so my application can work with it.
I understand there are some frameworks like shiny which act as web servers for R, but I can't find documentation on those frameworks on how to pass parameters via the URL so R can use them.
Ideally I will need to call a URL like:
http://127.0.0.1/R/param1/param2
And that URL will call an R script which will use param1 and param2 to perform some functions and return a JSON which I will then read from my app.
If you have not done so yet please checkout [DeployR]. You can also post questions to the DeployR Google Group for help.
For full disclose I am one of the authors of DeployR
Overview
DeployR is an integration technology for deploying R analytics inside web, desktop,mobile,and dashboard applications as well as backend systems. DeployR turns your R scripts into analytics web services, so R code can be easily executed by applications running on a secure server.
Using analytics web services, DeployR also solves key integration problems faced by those adopting R-based analytics alongside existing IT infrastructure. These services make it easy for application developers to collaborate with data scientists to integrate R analytics into their applications without any R programming knowledge.
DeployR is available in two editions: DeployR Open and DeployR Enterprise. DeployR Open is a free, open source solution that is ideal for prototyping, building, and deploying non-critical business applications.
DeployR Enterprise scales for business-critical applications and offers support for production-grade workloads, as well as seamless integration with popular enterprise security solutions such as single sign-on (SSO), Lightweight Directory Access Protocol (LDAP), Active Directory, or Pluggable Authentication Modules (PAM).
I am pretty new with R
Prefect. DeployR is intended for both the Data Scientist as well as the application developer who might not know R.
What I am trying to do is to be able to load a URL from another application
(Java) which will run an R script and output a JSON so my application can work with it.
DeployR does this quit well. To aid in the communication between your application
and the DeployR server (that will be executing your R) there are the DeployR Client libraries.
Depending on your needs, DeployR has out-of-the-box 'client library' support in:
Java-client-library: https://github.com/deployr/java-client-library
.NET-client-library: https://github.com/deployr/dotnet-client-library
JavaScript and Node.js-library: https://github.com/deployr/js-client-library
DeployR also supports the RBroker Framework
should your use-case or runtime anticipate a high-volume workload or the need for periodic, scheduled or batch processing.
I understand there are some frameworks like shiny which act as web servers for
R, but I can't find documentation on those frameworks on how to pass parameters
via the URL so R can use them
DeployR acts as your analytics engine through its APIS. Basically think of it as
turning your R scripts into secure analytic web services to be consumed like any
other web service.
Pass parameters
Passing parameters to an R Script in DeployR is easy, however you have to understand that you are passing parameters to an R Script from a language that is not R. As such, there is some 'Data Encoding' that needs to be done. For example, turn your Java String into an R character or your Java boolean to an R logical...
The DeployR Client library or RBroker makes this easy.
It sounds like you are using Java, so first review the Java tutorial java-example-client-basics https://github.com/deployr/java-example-rbroker-basics to give you some context then checkout the many Java examples under java-example-client-data-io https://github.com/deployr/java-example-client-data-io.
The example source is fully available so that should give you everything you need
in order to understand how to do basic I/O from your application to the DeployR server for your R analytics.
Ideally I will need to call a URL like:
http://127.0.0.1/R/param1/param2
I suggest using the DeployR Client libraries for your communication as described above, it does just that.
As always post questions to the DeployR Google Group https://groups.google.com/forum/#!forum/deployr for help.
You have some options to do that, IMHO OpenCPU is a nice one.
It's the simplest open source way to implement a web server to provide R computation as a REST service.
The creator of OpenCPU is the same author of jsonlite package, and you can easily get and pass json parameters with OpenCPU, as you can see here.
Another way to implement REST API web service in R is a plumber package (formerly rapier). It uses function decoration approach within special comments:
# myfile.R
#* #get /mean
normalMean <- function(samples=10){
data <- rnorm(samples)
mean(data)
}
# service.R
library(plumber)
r <- plumb("myfile.R") # Where 'myfile.R' is the location of the file shown above
r$run(port=8000)
Then invoke it:
curl "http://localhost:8000/mean"
Related
I would like to quickly list all Google Cloud projects in an organization, without AppScript folders.
gcloud projects list can be very slow. This documentation is about speeding it up, but does not show how to retrieve the Appscript folder which is used for filtering. Can that be done from the command line?
Also, gcloud projects list does not have a way to filter by organization. It seems that that is impossible as projects are not linked to their organization except through a tree of folders.
The documentation shows a way of walking the tree, apparently with Resource Manager API, which might do the job, but only pseudocode is shown. How can this be done with gcloud -- or else with Python or another language?
And if there is no way to accelerate this: How do I page through results using gcloud projects list? The documentation shows that page-size can be set, but does not show how to step through page by page (presumably by sending a page number with each command).
See also below for a reference to code I wrote that is the imperfect but best solution I could find.
Unfortunately there isn’t a native Apps Script resource available to work with Cloud Resource Manager API.
Although, it is possible to make a HTTP call directly to the Resource Manager API projects.list() endpoint with the help of UrlFetchApp service.
Alternatively, using Python as mentioned, the recommended Google APIs client library for python supports calls to Resource Manager API. You can find the specific projects.list() method documentation here.
On additional note, if you happen to use a Cloud project to generate credentials and authenticate the API call, you may want to enable Cloud Resource Manager API on your project by following this URL.
I’d also recommend submitting a new Feature Request using this template.
Here is some code that lists projects in an organization as quickly as possible. It is in Clojure, but it uses Java APIs and you can translate it easily.
Key steps
Query all accessible projects using CloudResourceManager projects(), using setQuery to accelerate the query by filtering out, for example, the hundreds of sys- projects often generated by AppScript. The query uses paging.
From the results
Accept those that are the child of the desired org
Reject those that are the child of another org.
For those that are the child of a folder, do this (concurrently, for speed): Use gcloud projects get-ancestors $PROJECT_ID to find the projects in your organization. (I don't see a way to do that in Java, and so I call the CLI.)
I'm trying to teach myself about integrating systems via WebHooks.
In a free/hosted GIS system, I can create a WebHook that would, in theory, POST a JSON object to an external system.
The problem is, I don't have an external system that's available right now for for receiving the POST.
I think I need some sort of publicly available sample server that would:
Receive the POST requests
Do something with the requests (ie. create some sort of record)
...so that I could determine if the WebHook worked correctly or not.
How can I test my WebHooks without having an on-premise external system?
I've poked around websites like Postman Echo and Amazon Lambda. But to my untrained eye, it seems like they're not quite designed for what I need.
You could use any of these options depending on your requirements:
You could use webhooks modules in services like Integromat or Zapier to receive webhook data and then apply transformation.
You could deploy a script on heroku and use the URL generated there to send the webhooks calls.
You could also use services like requestbin, webhook.site etc if you just want to receive webhooks data.
Regards
have been with mvc for a little while. the usual case when an action returning json, it is initialized by ajax in the view and the view is expecting info inside the json.
is there a case the action returning json to the view and is caught by something else instead of javascript? Thanks.
Yes, a JSON API can be consumed by a large variety of clients. It can be the browser sending an AJAX request, but it can also be a desktop application fetching data from the Internet, a server-side job scraping the data for analysis, etc.
For example, let's say you're running a stock exchange website, and you're publishing current stock values as JSON. You can use that JSON on your website to display the data, but you (or any other developer) can also write a desktop application which will get that data and process it on a local machine (to, for example, show the user which stocks they should buy). Or aggregate data from different sources.
Many websites make their APIs public, so that third party developers can write alternative clients, integrate the API's functionality in their own products, and so on. For example, GitHub's APIs are public - the GitHub website can utilize them for the AJAX requests, and GitHub for Windows can show you the list of repositories you own by making a request to that API using C#'s WebClient.
We have a requirement,where we need to provide data of HAWQ as a restful API to many consumers such as mobile app, web app etc in JSON format with web service security ;basically Data as a service to different applications from data lake.
Can you please help us with detail architecture or some pointers on the same. We are using Pivotal HD 3.0
I would say you could use any application to develop your webservices (ie: spring) and connect to HAWQ via the JDBC driver to query the data and then reformat it to JSON within your webservice.
Wikipedia definition:
In computer programming, an application programming interface (API) specifies how some software components should interact with each other.
I've seen some people consider an api of a library just as documentation. Like on api.jquery.com they show how the jquery library gets used. I've also seen people define an api as the visible parts of a library.
I understand how web api's work: There's an interface which you can use to interact with a webapplication using JSON or XML, e.g. youtube api. So I could get information about a youtube video or playlist.
I've read that there are different types of api's. Web api's, library api's, OS api's etc.
Here are some examples that I hope I can clear my confusion with.
Example 1
If I'd include a library in C++, then the header files would be the API? What about an api like Win32/Winapi. Why is this called an api and not a library? Don't I just include it into my source code and start using it?
Example 2
If I want to use a library in C# I'd add a .DLL to my bin folder and tell the compiler I want to use the library (i.e. using System.Web). Would the api just be all the public members (hence the visible parts) in the class that is written in the library?
Example 3
Lets say company X has written an MMORPG game but they do not have a website api. I want to make a windows application and I'd like to make it possible to view any character within my app. How would I communicate with the game to get this data? Where is the api written? How can I view it?
And what kind of an api would an operating system have? How could I use it? Any examples?
API is a contract between service provider and a service consumer (your program). This is it. How is it done, it's implementation specific.
A contract in a way that provider agrees to "If you call function X with parameter Y I promise you the result will be Z.". But client also agrees to "call function X with parameter of type T" and not any nonsense.
Ad1: Your code is a library. It can implement many hidden functions, eg void Nuke_hidden(double lat, double lon); which can strike any place in the world. But you can choose to not expose this method. Instead, have some other one which takes an enum parameter limited to New York, London, Moscow.
Now how your code does something is the body of your library. What you allow your consumers to do with it, is part of your API. Your contract specifically allows bombing only those 3 cities, and forbids bombing any other place.
Ad2: You got it. Exactly.
Ad3: If someone doesn't expose and document an API, it's usually because they don't want you to write such program : ). However they must have some sort of API (even if they never call it such), which the client uses to communicate with the server.
An API is just a definition how to interact with a software component. For example, an API for ebay could contain a function call to create an auction and a function call to retrieve all bids for an auction.
The API is neither some piece of software, nor the documentation, nor a DLL. The API is an abstract definition of how to "talk" to a piece of software. How it is implemented depends on the developer that provides the API.
Of course, to tell other programmers how to use your software, you need to provide documentation of the API. That is: What calls are available? Which parameters do they require and accept?
So, regarding example 1) The header file would define how to use your API using C++. Just like for Windows. Windows has an API (that is: an interface applications can use to create windows, textboxes, etc.). The header files define how to use that from C++.
Regarding example 2) A .NET DLL is a way for a piece of software to interact with an API from managed code. You could say that every class in C# defines an API in that it has public members.
Regarding example 3) Not every piece of software provides access to its internals to other software. For example: Word does have an API you can use to create add-ins. Other software does not provide such an API.