Integrating R view with Javascript

LabKey Support Forum (Inactive)
Integrating R view with Javascript bront  2013-11-12 10:02
Status: Closed
 
hi,

I am trying to call a saved R view via LABKEY.QueryWebPart. The data grid appears, but I can't see the R view (a bar chart).

The viewName matches the saved R view.

I may be going wrong with the updateURL, but currently my R view requires no params to run (everything is hard coded)

Should I perhaps be using LABKEY.WebPart() instead of QueryWebPart?

q = new LABKEY.QueryWebPart({
      renderTo: 'queryTestDiv1',
      title: 'test',
      schemaName: 'epi',
      queryName: 'water',
      viewName:'chart_view2',
      buttonBar: {
        includeStandardButtons: true
        },
        updateURL:'/epidemiologic_data/begin.view?qwp1.queryName=water&xaxis=age_cat&yaxis=cr&qwp1.reportId=db%3A299'
});

Many thanks,

bront
 
 
jeckels responded:  2013-11-12 12:13
Hi Bront,

Yes, you'll want to use LABKEY.WebPart instead, with a partName of 'Report'. Here's an example:

    function refreshChart() {
        var config = {reportId: '101', showSection: 'labkeyl_png'};

        var wikiWebPartRenderer = new LABKEY.WebPart( {
            partName: 'Report',
            renderTo: 'histogramDiv',
            frame: 'none',
            partConfig: config
        });
        wikiWebPartRenderer.render();
    }

You can get the reportId from the URL when you're editing the R view. The format depends on whether it's stored in the database (as it is when it's created through the user interface), or from a file in a module.

You can view the example in action here:

https://www.labkey.org/Wiki/home/CPAS/demo/page.view?name=Fractional%20Delta%20Mass

You can either just view the page's source code via your browser, or download the files from here:

https://www.labkey.org/FileContent/home/CPAS/demo/begin.view

Thanks,
Josh
 
bront responded:  2013-11-12 13:10
Josh,

Works perfectly. Thanks for pointing me in the right direction... now one more question.

I need to pass some parameters into the WebPart R-script. Initially, I was trying to do this via url.params, but I am wondering if there is a way to do it via the partConfig (or some other way).

Thank you,

bront
 
jeckels responded:  2013-11-12 14:08
Hi Bront,

Yes, you can. For clarity, I had actually snipped that out of the source I stole from. Here's the full thing:

    function refreshChart() {
        var config = {reportId: '101', showSection: 'labkeyl_png'};

        if (comboBox.getValue() != null && comboBox.getValue() != "") {
            var filter = LABKEY.Filter.create('Run/ExperimentRunLSID/RunGroupToggle/' + comboBox.getValue(), 1, LABKEY.Filter.Types.EQUAL);
            config[filter.getURLParameterName()] = filter.getURLParameterValue();
        }

        var wikiWebPartRenderer = new LABKEY.WebPart( {
            partName: 'Report',
            renderTo: 'histogramDiv',
            frame: 'none',
            partConfig: config
        });
        wikiWebPartRenderer.render();
    }

It happens to pull the value from an ExtJS combo box, but you should be able to easily adapt to whatever filter values you want to apply.

Thanks,
Josh
 
bront responded:  2013-11-13 12:42
Josh,

Great. I noticed that bit in the code after I asked.

I really appreciate your prompt and clear help.

cheers,

bront