Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Not applicable

Using Nested R Functions with Qlik Sense Extension, R, and Open CPU Integration Approach with Open CPU Defaults?

Hello, as someone with a fair amount of R experience who is brand new to Qlik, I was very excited to find some of the work that has been done to create Qlik Sense Extensions that use R's capabilities via Open CPU:

Unfortunately, I am struggling to figure out how to use some basic R commands in this setup because I will have to use the default Open CPU R packages and so cannot create custom R functions as in GitHub - aasensior/sense-r: Functional examples on integrating Qlik Sense and R.

For example, how would one return the R console output for the summary (to see significance levels and more) of a linear regression object in this setup?  In R, using the packaged "cars" dataset, that might be done with "summary(lm(cars$speed~cars$dist))".  However, I am not sure how to nest the "lm" function within the "summary" function, especially when the "summary" function is found in https://public.opencpu.org/ocpu/library/base/R/ and "lm" in https://public.opencpu.org/ocpu/library/stats/R/.

The function "lm" alone is used around line 69 in https://raw.githubusercontent.com/nodtvedt/qlik-sense-r-regression-extension/master/qlik-sense-r-reg....

How would that script need to be changed to return the summary of the linear regression object instead?

These may be beginner questions, but any help would be greatly appreciated!

1 Reply
Not applicable

Re: Using Nested R Functions with Qlik Sense Extension, R, and Open CPU Integration Approach with Open CPU Defaults?

There is a function summary.lm (look at https://public.opencpu.org/ocpu/library/stats/R/). This can be called with the result of the lm function.

OpenCPU - JavaScript Client‌ explains how to combine function calls by sending the session key of the first function call (lm) to the summary.lm function.

An example:

var req1 = ocpu.call("rnorm", {n: 100}, function(session1){
    var req2 = ocpu.call("var", {x : session1}, function(session2){
        session2.getObject(function(data){
            alert("Variance equals: " + data);
        });
    });
});
Community Browser