Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
harjeetjudge
Product and Topic Expert
Product and Topic Expert
12,897
SAP Analytics Cloud (formerly known as SAP BusinessObjects Cloud) provides the ability to embed an R visualization in a story to enhance insights available to the business user.



This blog will cover how to setup R-Server on Linux for use with SAP Analytics Cloud.  The setup involves the following steps:

  1. Install gcc, openssl, and R on Linux

  2. Generate ssl certificate

  3. Install and configure RServ package

  4. Setup RServe in SAP Analytics Cloud

  5. Add additional R packages


Step 1: Install gcc, openssl and R


This step is different depending upon what version of Linux flavor is being used.  I've documented the steps for Suse12 x86_64 version.  Check the version of your Linux distribution using command relevant for your OS.



Install gcc

First step is to find the version of gcc corresponding to your Linux version.  To find your version of gcc:



  • Make note of the entry that matches Linux version you are using.  In my case, the version of Suse is SLE-12.

  • Run the commands below one at a time.  Substitute <version> with your Linux version.


zypper ar http://download.opensuse.org/repositories/devel:/gcc/<version>/ devel-gcc



If prompted to trust the key, choose option 'a'



Note: If there are any error prompts like the one below, choose option 'i' to ignore the errors.



zypper refresh

zypper install gcc

Install R



  • Run the following commands in your Linux console one at a time.  Substitute <version> with the Linux version you are using.  In my example the <version> is SLE_12_SP1.


zypper addrepo -f http://download.opensuse.org/repositories/devel:/languages:/R:/released/<version> R-base

zypper install R-base R-base-devel

Install openssl

  • Run the following commands in Linux console:


zypper install openssl

zypper install openssl-devel

Step 2: Generate SSL Certificates



  • Navigate to /tmp or a directory of your choice.

  • Run the following commands:


mkdir Rserv
cd Rserv
mkdir CA
cd CA
openssl genrsa -out Rserve.key 2048
openssl req -new -key Rserve.key -out Rserve.csr

Note:
When you create the CSR you will need to enter some information for the certificate, everything is optional.



openssl x509 -req -days <numdays> -in Rserve.csr -signkey Rserve.key -out Rserve.crt

Replace <numdays> with the number of days for eg: 365

  • Save the Rserve.crt file to your local computer (or copy all the text).  You will need to import this file in SAP Analytics Cloud later.


Step 3: Install and configure RServ package


Create RServe config file

  • Make the workspace directory which will be /tmp/Rserv/workspace.


cd /tmp/Rserv
mkdir workspace

  • Create a file called Rserv.conf under /etc directory using vi or other text editor with the following contents:


workdir /tmp/Rserv/workspace
remote enable
auth required
plaintext disable
port 6311
maxsendbuf 0
tls.key /tmp/Rserv/CA/Rserve.key
tls.cert /tmp/Rserv/CA/Rserve.crt
tls.port 6312
qap disable 6311

Note: The config is customizable if desired. Here are what the options mean:
workdir: directory for temp files in R to be created and used.
remote: whether you need remote access. This must be 'enable' to be used in SAP Analytics Cloud
auth: whether the username / password fields will be checked. 'required' is recommended
plaintext: use plaintext when passing credential information. 'disable' is highly recommended
port: default port for non-encrypted connection. Default is 6311.
maxsendbuf: maximum send buffer size. 0 is the default and it means unlimited.
tls.key: path to the key
tls.cert: path to the certificate
tls.port: port for an encrypted connection

We use 'qap disable' to disable the normal un-encrypted port(6311 in this case). Remove this if you want to use it.

Install Rserve

  • Run the R shell using the command below:
    R

  • In the R shell run the commands below to Install Rserve
    install.packages("Rserve")
    q()




Notes:
Running 'install.packages("Rserve")' prompts you to chose a mirror for download. Choose the closest geographical location for best results.
Use q() to close the R shell

Create secondary user
It's good idea to create a secondary user with less privileges to run Rserve to minimize the damage that can be done by a malicious user.

Create  a new Linux user and set the password. We will use the user/password in Step 4 later. Choose any that you like but they must be consistent with the followed steps.
After closing the R shell run the following commands:

useradd <someuser>
passwd <someuser>
<create a password through the prompts>



Give the user access to the workspace folder. To run R in SAP Analytics Cloud we require some temporary files to be created so this user needs to be able to write to the work directory (ie. /tmp/Rserv/workspace)

Run the commands below:

cd /tmp/Rserv
chown -R <someuser> workspace

We also want to restrict the user from accessing the authentication keys.  Run the command below to change security setting on the folder:

chmod -R 700 CA

 

We can now change Rserve configuration so that the commands execute as the restricted user we just created.  Run the command below to gid and uid numbers for the user we created.

id <someuser>



Make note of the gid and uid (numbers)

Edit the /etc/Rserv.conf file and add the following lines:
gid <group-ID>
uid <user-ID>



Run the command below to start RServe
R CMD Rserve

Optional step to improve performance

To improve performance of R script execution, create a Rprofile and include the libraries that you use in your Rscript in the file.  This will pre-load the libraries that you use most.

  • sudo su ruser

  • vi ~/.Rprofile


Add the libraries you use in your script in the .Rprofile and save the file.  For eg:

  • library(ggplot2);

  • library(dply)


Kill and Restart Rserve process

Step 4: Setup R-server in SAP Analytics Cloud


We are not ready to configure SAP Analytics Cloud to use the R-Server.

  • Log into SAP Analytics Cloud

  • Choose System >> Administration option




  • Edit(pencil icon in the top right) the RServe configuration:


host: <hosname or IP address of R server machine>

port: 6312

certificate: <paste your certificate(from step 2), or upload the saved certificate file>

username: <Linux user running RServe.  See step 3>

password: <Password for Linux user running RServe.  See step 3>



  • Click "Check Configuration" to verify a connection can be made.

  • If the verification step is successful, save the connection.


Step 5: Add additional R packages


Once the connection is successful we can install the additional R packages required for SAP Analytics Cloud.  Specifically we will Install "ggplot2", "jsonlite", "bit64", "data.table" packages.

If you used SUSE, we have to install c++, which is required for ggplot2.

  • Run the command below to install c++


zypper in gcc-c++

  • In Linux console type R to run the R shell.

  • Type the following command:


install.packages(c("ggplot2", "jsonlite", "bit64", "data.table"))

  • Restart Rserve after installing the packages using the steps below:


ps -ef | grep Rserve
kill <pid> (where pid is the process id for RServe)

  • Run: R CMD Rserve


You are now ready to embed your R visualizations in your SAP Analytics Cloud story.  For details on how to embed R-visualizations in SAP Analytics Cloud follow the blog below:

https://blogs.sap.com/2017/05/26/hands-onhow-to-leverage-r-visualization-feature-in-sap-analytics-cl...

Q&A


Q: Where do I install R-Server Installed?

A: The R-Server can be installed on-premise or in the cloud(AWS, Azure etc).  If it's installed on-premise, the R-Server port(6312 in my case) must be exposed to internet so that SAP Analytics Cloud can connect to it.

Q: Can I install the server in Windows instead of Linux?

A: At the moment on R-Server deployed on Linux is supported.  While technically Windows installation is possible and may work, we haven't tested this configuration internally.

Q: Will SAP provide a hosted R-Server ?

A: SAP provides R-Server for tenants in US1US2EU1, and AP1.  Check here for updates and also to get a list of supported packages in hosted R environment.

Q: Can I choose other flavors of Linux or does the install have to be on Suse?

A: Yes, you can choose other Linux flavors like Redhat or Ubuntu.  I will update the blog with detailed steps to install on these Linux distributions at later time.

Q: What versions of R are supported?

A: See table below for minimum supported versions.  At the time of writing the R version that is installed using the steps above is 3.4.0.



Q: What R packages are supported?

A: We support R packages that output in svg, png or html format.

See Also


18 Comments