Qlik Sense is a tool for exploratory data analysis and visualisation. It’s powerful and versatile. It’s can, however, be significantly enhanced by interfacing with R. Qlik Sense does not currently integrate directly with R. However, it’s not too tricky to get the two systems talking to each other. We’ll need two things to make this happen:
- Rserve — A TCP/IP server which allows other programs to use R without initialising a separate R process or linking against an R library; and
- SSE R-plugin — A server-side extension (SSE) which provides the interface between Qlik Sense and Rserve.
SSE Plugin on Windows
Getting Qlik Sense to talk to Rserve on a Windows machine is a relatively simple process. There’s a document with detailed instructions here. This is a brief summary:
- Install a recent version of R. Select the 64-bit version during installation.
Run R and install the Rserve package.
Install other R packages. The list of packages will depend on what functionality you want to use, but this is a good start.
install.packages(c("jsonlite", "forecast", "rpart", "partykit"))
Load and run Rserve.
Configure Qlik Sense Desktop to find the plugin by editing the
Settings.iniwhich you’ll find in
\Documents\Qlik\Sense\within the user’s home folder.
[Settings 7] SSEPlugin=R,localhost:50051
Download and install the SSE R-plugin.
Launch the plugin by running
This is fine if you are happy with running everything in a Windows environment. This, however, is not what we want! Rather we prefer to host Rserve and the plugin on a separate Linux machine (probably in the Cloud), making it accessible to multiple Windows clients.
SSE Plugin on Linux
The SSE R-plugin is written in C#. It’s fairly simple to build under Windows. Getting it up and running under Linux requires a bit more work. There is a fork of the SSE R-plugin repository which builds the C# code using Mono and then wraps the result in a Docker image. However, it was forked midway through 2017, so it’s missing recent development on the plugin.
It was a but if a slog, but we figured out how to get the current plugin to build with Mono. To ensure that it will still build in the future, we have fixed on a specific build of the Mono Docker image and a particular commit on the SSE R-plugin repository. We also wrapped Rserve up in a separate Docker image, again choosing a specific version for reproducibility.
Now it’s just a question of running
docker-compose up on the Linux machine. This creates containers for Rserve and SSE R-plugin, which communicate via port 6311. The latter container exposes port 50051, which is used for the connection from Qlik Sense.
Before connecting from Qlik Sense it’s necessary to tweak the settings file, replacing
localhost with the IP address of the Linux machine.
[Settings 7] SSEPlugin=R,192.168.0.4:50051
At this point you’re ready to connect from Qlik Sense to the remote Rserve instance.
In the SSE R-plugin repository there’s a
sense_apps/ folder which contains a few example applications. There’s also a sub-folder with a couple of Qlik Sense extensions which need to be installed before running the examples.
Once the extensions are installed, simply drag any of the
.qvf files under the
sense_apps folder onto the Qlik Sense desktop. Below is the Decision Tree app, which uses R to build a model on the Titanic data.