Developing a Shopify App With R

Shopify Partner
13 0 7

Hi, I was wondering if it's possible to build a shopify app using R (specifically  Has anyone done or seen this?

Pre-emptive response to "Why don't you use Rails?"

There's a big community of data scientist like me who are good with crunching numbers and building models in R, but suck at web development.  R Shiny makes it easy to build web apps, so we can focus on what we're good at - statistics.  So, if only I could integrate R with Shopify I think I could build some really cool stuff (e.g. product reccomendation engines, customer lifetime value estimator, etc.)

What I've tried so far

Using the httr package, I was able to "install" an app on a dev store, and then query that store's orders.  This looks like

# OAuth Methods

apikey <- "my_api_key89338f84fhp349hr"
secret <- "my_secret_keyf89j438f0j239fn4"

# Get the access_token

getToken <- function(storename="bens-test-store-4"){
  # Returns the shopify_token
  shopify_endpoints <- oauth_endpoint(authorize=paste0("https://", storename, ""),
                                      access=paste0("https://", storename, ""))
  shopify_app <- oauth_app("shopify", key=apikey, secret=secret)
  shopify_token <- oauth2.0_token(shopify_endpoints, shopify_app, scope="read_orders")

# Make requests

getOrders <- function(storename="bens-test-store-4", token){
  req <- GET(paste0("https://", storename, ""), authenticate(user=apikey, password=token$credentials$access_token))
  orders <- content(req, as="parsed")

shopify_token <- getToken()

What's making my brain spin is how the flow of user authentication works.  For example, suppose my app lives at  When someone goes to, a few situations could arise

  1. User has already installed myapp and is currently logged in
  2. User has already installed myapp and is not logged in
  3. User has not installed myapp

How do people check for each of these scenarios and accordingly 1) prompt the user to sign up, 2) prompt the user to login, or 3) Display the user's data (assuming he is logged in)?

Replies 2 (2)
Shopify Staff (Retired)
Shopify Staff (Retired)
533 1 105

Hey Ben,

It's definitely interesting to hear of someone building Shopify applications in R -- I wasn't aware of the potential for building web applications with R.

The most naive approach here is to simply perform the OAuth handshake every time. This is the method described in the tutorial here. Upon redirecting the merchant to the installation URL (e.g. http://#{shop}/admin/oauth/authorize?client_id=#{@key}&scope=#{scopes}&redirect_uri=https://#{@app_u...), the user will be prompted with an installation screen if they have not yet installed the app. If the app is already installed, they will simply be redirected to the redirect_uri immediately.

A more complicated login flow would involve using sessions. You can take a look at our example Rails application shopify_app for some insight on this.

Hope this helps. Happy building!



Jamie | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

New Member
1 0 0

Hi @Ben83 

As a fellow data scientist I had just the same idea. Did you finally manage?