This is an optional step. If you wish you can skip to the last step in the tutorial: Step 4: Summary Report For Managers

To further explore the possibilities available, let's add an R data visualization plot of the "Reagent Requests" list to the confirmation page, to create a page that looks like the following:

Set Up R

If you have not already configured your server to use R, follow these instructions before continuing: Install and Set Up R.

Create an R Histogram

  • Click Start Page.
  • Go to Admin > Manage Lists.
  • On the Available Lists page, click Reagent Requests.
  • Select Reports > Create R Report.
  • Paste the following code onto the Source tab (replace the default contents).
if(length($userid) > 0){
hist($quantity, xlab = c("Quantity Requested", labkey.url.params$displayName),
ylab = "Count", col="lightgreen", main= NULL)
} else {
write("No requests are available for display.", file = "${txtout:histogram}")
  • Check the "Make this report available to all users" checkbox.
  • Scroll down and click Save.
  • Enter a Report Name, such as "Reagent Histogram".
  • Click OK.
  • From the data grid, select Reports > "Reagent Histogram"
  • Click OK.
  • Click the Report tab to see the R report.
  • Notice the reportId in the URL. You will need this number to reference the report in your confirmation page. In this URL example, the reportId is 90:


http://localhost:8080/labkey/list/home/Reagent Request Tutorial/grid.view?listId=1&query.reportId=db:90

This histogram gives a view of all requests listed in the "Reagent Requests" table.

Update the Confirmation Page

  • Open the confirmation wiki page for editing.
  • Add the following to the block of <div> tags at the top of the page:
<div id="reportDiv">Loading...</div>
  • Add the following to the init() function:
// Draw a histogram of the user's requests.
var reportWebPartRenderer = new LABKEY.WebPart({
partName: 'Report',
renderTo: 'reportDiv',
frame: 'title',
partConfig: {
title: 'Reagent Request Histogram',
reportId: 'db:XX',
showSection: 'histogram'
  • Note the reference "db: XX". Replace XX with the report number for your R report.
  • Click Save and Close.

You will now see the histogram on the Reagent Request Confirmation page.

Link to a live example.

Note that the R histogram script returns data for all users. The wiki page does the work of filtering the view to the current user by passing a filtered view of the dataset to the R script (via the partConfig parameter of LABKEY.WebPart). To see the web part configuration parameters available, see: Web Part Configuration Properties.

When creating a filter over the dataset, you will need to determine the appropriate filter parameter names (e.g., 'query.UserID~eq'). To do so, go to the dataset and click on the column headers to create filters that match the filters you wish to pass to this API. Read the filter parameters off of the URL.

You can pass arbitrary parameters to the R script by adding additional fields to partConfig. For example, you could pass a parameter called myParameter with a value of 5 by adding the line "myParameter: 5,". Within the R script editor, you can extract URL parameters using the labkey.url.params variable, as described at the bottom of the "Help" tab.

Previous Step | Next Step





expand all collapse all