This topic is under construction for the 17.3 release of LabKey Server. For current documentation of this feature, click here.

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

  • Return to the home page of your "Reagent Request Tutorial" folder by clicking the Reagent Request Tutorial link or using the project and folder menu.
  • Select (Admin) > Manage Lists.
  • In the Available Lists grid, click Reagent Requests.
  • Select (Reports) > Create R Report. If this option is not shown, you must configure R on your machine.
  • Paste the following code onto the Source tab (replacing 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 the Report tab to see the R report, if it is not selected by default.
  • Notice the reportId in the page URL. You will need this number to reference the report in your confirmation page. In this URL example, the reportId is 90.
    • The "%3A" is the encoded colon ":" character and "%20" represents a space.

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. We will make three changes to customize the page:
  • Add the following to the end of the block of <div> tags at the top of the page:
    <div id="reportDiv">Loading...</div>
    • This will give users an indication that additional information is coming while the histogram is loading.
  • Uncomment the line marked with "// Uncomment below to filter the query to the current user's requests."
    filters: [ LABKEY.Filter.create('UserID',],
    • This will reduce the grid displayed; if you have not entered any sample requests, an empty table will be shown.
  • Add the following to the init() function after the "//Extract a table..." section:
// 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