Skip to Content

SAP Analytics Cloud(formerly SAP BusinessObjects Cloud) provides the ability to embed an R visualization in a story to enhance the 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

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 doesn’t provide a hosted R-Server.  We may look to provide this in the future.

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 or png format.  Other output types(eg. html) are not supported.

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Wim Peers

    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?

    (0) 
    1. 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

      (0) 
      1. Wim Peers

        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)

         

         

        (0) 
        1. 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

          (1) 
          1. Wim Peers

            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

             

             

            (0) 
  2. Harjeet Judge 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

    (0) 
  3. Wim Peers

    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.

     

    (0) 
    1. Harjeet Judge 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.

      (0) 

Leave a Reply