Skip to Content
Author's profile photo Harjeet Judge

Setup R server for use with SAP Analytics Cloud

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:

  • Open the following URL in a browser window: http://download.opensuse.org/repositories/devel:/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

  • Find your version from http://download.opensuse.org/repositories/devel:/languages:/R:/released/

  • 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-cloud-to-achieve-your-data-analysis-goal/

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

Assigned Tags

      17 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi, I am unable to make link between Analytics cloud and Rserve instance using the settings listed in the manual. At the same time I can telnet to Rserve on the specified location, and I receive proper response from the server.

      I am running Rserv on Ubuntu 16.04 - R version is 3.4 and Rserve 1-7-3. (But I tested also 1.8-5 and 1.8-4)

      Depending on the settings in the /etc/Rserv.conf file, I receive error messages. Using telnet I am able to connect to Rserv and I receive the proper response (cf. manual Rserve)

      using settings from the pdf file :

      • R service is currently unavailable

      using adapted config file with disabled encryption:

      • R service failed to process your request

      using adapted config file with enabled encryption

      • Connection to host failed:

       

      Anybody succeeded to launch RServe Analytics cloud on Ubuntu? What settings did you use?

      Author's profile photo Denis Markman
      Denis Markman

      It seems the encrypted port isn’t configured right – in case the service is running you’ll get the “service failed to process your request”.

      Try to check:

      1. Configuration Rserv.conf
      2. “netstat -na” – if the port is listening
      3. “telnet <rserve host> port” – are the port/host available from outside
      4. “R CDM Rserve.dbg” – you’ll see if the correct conf file is read and output of the requests

      Anyway I have  similar problem but at the authentication step.

      Denis

      Author's profile photo Former Member
      Former Member

      Hi Denis,

      thx for the reply, it seems that we are stuck on the same step => authenticated connection to the server not working. Below some more explanations on what I tried. In short Telnet connection works, but Analytics cloud cannot communicate with Rserve on my machine.At the end the dbg server shows that connection was reset by peer, so this means that the connection was initiated, but that it also got terminated by Analytics cloud for some reason.

      -------- extra info below----------

      When using the settings from the blog :

       

      • SAP Analytics cloud: Connection to host failed - Unable to retrieve the external data
      • RServe.dbg : connection is accepted, calling connected
      • telnet : connection is made, and anything I type in telnet is shown on dbg server. (e.g "hello" from telnet is repeated on Rserve)

      When running Rserve.dbg without any authentication or encryption enabled:

      - on Analytics Cloud => R service failed to process your request

      - the dbg output shows that a connection is made but ends with connection closed by peer

      -telnet => output from documentation : RSRV0103QAP1 (the dbg server shows now that idstring is sent)

       

       

      Author's profile photo Denis Markman
      Denis Markman

      Hi Wim

      I'm trying to debug authentication process(with our basis guys).

      But meanwhile I've succeeded in setting up non encrypted connection that works. My Rserv.conf:
      workdir /Rserv/workspace
      remote enable
      auth disable
      plaintext disable
      port 6311
      maxsendbuf 0
      tls.key /Rserv/CA/Rserve.key
      tls.cert /Rserv/CA/Rserve.crt
      tls.port 6312
      gid 1001
      uid 1001

      I'll send an update if we find smth on ssl.

      Denis

      Author's profile photo Former Member
      Former Member

      Hi Denis,

      Thx again for coming  back to me.  I solved the non-encrypted as well yesterday. It was a permission issue for me. Seemed there were actually two issues causing the same error message:

      • either I started the process with my personal 'non-Rserve' account, which did not had write access to the workspace folder.
      • or I started the Rserve process,while I was in my personal 's account (non-Rserve) home folder, where the Rserve account did not had proper rights.

      Solving either one of these allowed me to have access to the server. So giving my personal account writing access to the workspace folder or only starting up Rserve when I was in a folder where the Rserve account had proper permissions. For security reasons I end up with the second option.

      I will also continue to look into this further, and I will post back here as well.

      Wim

       

       

      Author's profile photo Harjeet Judge
      Harjeet Judge
      Blog Post Author

      You can also try to comment out the lines below in your Rserve.conf file and run the service as root user to avoid any permissions issue.  In addition, make sure RServe port is accessible from the Internet.

      #gid 1001
      #uid 1001

      Author's profile photo Former Member
      Former Member

      Hi Harjeet,

      thx for the suggestion , but running Rserve as root is a security risk, so will not solve anything.

      I finally found a solution: if you want to use user name and password to encrypt/login, you need to add/change the following things to config file /etc/Rserv.conf

      • passwd <full path to file> e.g /etc/Ruser.txt
      • plaintext disable

      create Ruser.txt file in /etc

      add a line for each user with their password separated by a space

      user1 passwd1

      This solved it for me.

       

      Author's profile photo Harjeet Judge
      Harjeet Judge
      Blog Post Author

      Agreed on running as root user posing a security risk. My intent with comment was to only to use it for troubleshooting purposes.

      Author's profile photo Former Member
      Former Member

      Hi Harpreet,

      I followed the same procedure as described above. Installation was successful. Installed R version 3.4.1 and Rserve 1.7.3.

      I am also getting the same error while trying to establish connection from Cloud Analytics to Rserve (On-Prem) " Unable to retrieve the external data due to: Connection to host failed:.

      I have created a user ruser to run the Rserve. All the files related to R, Rserve, Rserve.conf is owned (have full permission to) by ruser. I can telnet to localhost 6312/11.  I have tried connecting by disabling and enabling encryption. Also tried running the Rserve with root, but it could not establish the connection. Please let me know what else I can try to fix the issue.

      Thanks,

      Satish

       

      Author's profile photo Kiran Sarma
      Kiran Sarma

      Hi Satish,

      Would like to know if you managed to resolve your issue?

      Rgds,

      Kiran

      Author's profile photo Mohamed Judi
      Mohamed Judi

      Hi Harpreet,

      Thank you for this nice blog. I walked through your steps and everything worked like a charm. I just had to adjust some commands since I'm running my R server on an Ubuntu instance.

      As I said, all ran fine and I was able to execute example scripts in SAC. However, when I tried to be creative and use a package installed from Github via devtools, I got an error:

      Warning in dir.create(www_dir) : cannot create dir '(null).1003.1003/viewhtml2286683e12f', reason 'No such file or directory'

      Error in value[[3L]](cond) : cannot change working directory

      The script I'm trying to run is:

      library(dplyr)
      library(babynames)
      library(streamgraph)
      library(magrittr)
      
      babynames %>%
        filter(grepl("^Kr", name)) %>%
        group_by(year, name) %>%
        tally(wt=n) %>%
        streamgraph("name", "nn", "year")

      Thank you in advance for your help,

      MJ

      Author's profile photo Lewin Schaudt
      Lewin Schaudt

      Hi Mj,

       

      I had a similar error for version 1.7.3.. I was able to fix it by upgrading the Rserve version to 1.8.7..

      Kind regards,
      Lewin

      Author's profile photo Mohamed Judi
      Mohamed Judi

      Thank you for letting me know, Lewin Schaudt!

      Author's profile photo Radim Vongrej
      Radim Vongrej

      Hi Harjeet,

      As I am currently using SAC and R libraries, I’ve noticed that the “Shiny” library is already preinstalled. So my question is, whether it is possible to create interactive data visualization using Shiny App in R ? I know that the Shiny app has to be deployed somewhere on the Web, but I am wondering whether you already have any experience on that topic in the SAC environment.

      Thanks, Radim

      Author's profile photo Harjeet Judge
      Harjeet Judge
      Blog Post Author

      Hi Radim,

      It's possible to use the "Web Page" widget in SAP Analytics Cloud to embed a Shiny Application hosted on the web.

      I installed a Shiny Server on my system using this blog and used the Web Page widget to display a sample Shiny App in SAP Analytics Cloud.  Few things to keep in mind:

      1. We can't pass data from SAC to the Shiny app.
      2. You will need to follow SAC documentations on How to Embed a Web Page.

       

      Author's profile photo Bright Abu-sakyi
      Bright Abu-sakyi

      Hello Harjeet,

      Great. I have a question. I would like to know if Live connection works with integrating the R server on SAP analytics cloud.?

       

      Thanks Harjeet.

      Author's profile photo Mohamed Ben Hmida
      Mohamed Ben Hmida

      Hi Harjreet,

       

      Thank you for this nice blog,

      Can we build interactive charts with R viz on SAC . (plotly,highcharter,d3,...)  ??

       

      Thanks