Qlik Community

Ask a Question

Qlik Sense Documents

Qlik Sense documentation and resources.

Announcements
Support Cases coming to Qlik Community Oct. 4! Start chats, open cases, explore resources: READ DETAILS

Qlik Sense and R integration: ggplot and other visualizations, aggregation and data sorting

lorenzoconforti
Specialist II
Specialist II

Qlik Sense and R integration: ggplot and other visualizations, aggregation and data sorting

 

I’ve been working with Qlik for the last four years and in the past few months I’ve been more and more involved into bringing R functionalities into my dashboards. The integration works well but there are clearly some limitations, especially when compared to other solutions on the market; Qlik in my opinion still has a significant edge in terms of performance and associative engine and, when combined with R, it brings unique functionalities and features.

The purpose of this document is to review such limitations and provide solutions with the aim of fully utilising all R capabilities in Qlik Sense; there are Qlik extensions that provide some of these features but, although very well developed and implemented, they are limited to the type of analysis they can perform; also, they require a certain level of technical skills to adapt them to the bespoke needs that very often arise when working with R.

These are the 3 topics I will cover in the document:

  • ggplot and other visualizations: how to easily and effectively display in Qlik Sense any kind of R visualization without the need to develop bespoke extensions
  • Data aggregation through concatenation: how using the aggregation function allows to pass to R more complex data frames
  • Data sorting: how data is exchanged between Qlik Sense and R and how to handle sorting

1.png

2.png

3.png

4.png

 

I hope you'll find this useful

Please let me know if you have any comment or questions

Lorenzo

 
Attachments
Comments
lorenzoconforti
Specialist II
Specialist II

@thaisnsb 

Glad you find it useful

Here you can find the instructions on how to integrate R and Qlik Sense: 

https://community.qlik.com/t5/Qlik-Server-Side-Extensions-Documents/Installing-R-with-Qlik-Sense-pdf...

If you have any issues I suggest you search the forum as there are a few threads about it

 

Lorenzo

thaisnsb
Contributor
Contributor

Thanks Lorenzo

0 Likes
cmavp
Contributor
Contributor

Hello, @lorenzoconforti ! 

I would like to ask whether we can embed plotly (wrapping the plot created by ggplot2 with ggplotly) into Qliksense using this framework.

This is my attempt to adjust a syntax from R_Integration.qvf :

='
<div>
<iframe src="data&colon;text/html;base64,

$(=R.ScriptAggrExStr( 'NNS',
'
#delete any device that might still be active
if (length(dev.list())>0) { for (i in dev.list()[1]:dev.list()[length(dev.list())]) {dev.off()}};

#load libraries
library(tidyr);
library(dplyr);
library(RCurl);
library(ggplot2);
library(plotly);

 

#create a png temp file; generate plot
tf1 <- tempfile(fileext = ".html");
p<- ggplotly(
ggplot(q, aes(x=petalLength, y=petalWidth, color=species))
+ geom_point()
+ geom_smooth(method="loess")
);

htmlwidgets::saveWidget(as_widget(p), tf1)
dev.off();
txt <- base64Encode(readBin(tf1, "raw", file.info(tf1)[1, "size"]), "txt");
print(txt);


',

[Petal.Width] as petalWidth, [Petal.Length] as petalLength, Species as species

)
)



" height="100%" width="100%"></iframe>
</div>
'

But there is no result shown.

 

Thanks a lot beforehand!

 

Best Regards,

Vinz

0 Likes
lorenzoconforti
Specialist II
Specialist II

Hi @cmavp ,

Does this code work in R (I mean, outside of Qlik Sense)? Have you installed the libraries in the Qlik R environment?

I can't troubleshoot it at the moment. Start sink to see what's going on at a console level.

Lorenzo

0 Likes
cmavp
Contributor
Contributor

Hi @lorenzoconforti ,

Yep, the output from ggplotly itself has been successfully generated (as an html file in tmp directory of QS Server, as well as when I tried it in my local PC), so the next steps (which probably become the source of the problem) are to convert to base64 and to embed it to the html template of QS Media Box.

Actually, the conversion to base64 until print(txt) part also has been successfully done, but I'm not sure whether it is the desired output or not.

It is my first time knowing about sink. Do you have any advice on how I should utilize this tool?

 

Thanks a lot!

 

Best Regards,

 

Vinz

0 Likes
lorenzoconforti
Specialist II
Specialist II

@cmavp 

sink is an R function that can be used to  redirect the output of the console to a txt file so that you can see what is happening

https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/sink

Have a go at this; at least it should clarify what's happening

 

 

 

0 Likes
Version history
Revision #:
7 of 7
Last update:
‎2019-10-29 06:02 PM
Updated by:
 
Contributors