This is an optional step. If you wish you can skip to the last step in the tutorial: Step 4: Summary Report For Managers
If you have not already configured your server to use R, follow these instructions before continuing: Install and Set Up R.
if(length(labkey.data$userid) > 0){
png(filename="${imgout:histogram}")
hist(labkey.data$quantity, xlab = c("Quantity Requested", labkey.url.params$displayName),
ylab = "Count", col="lightgreen", main= NULL)
dev.off()
} else {
write("No requests are available for display.", file = "${txtout:histogram}")
}
This histogram gives a view of all requests listed in the "Reagent Requests" table.
<div id="reportDiv">Loading...</div>
filters: [ LABKEY.Filter.create('UserID', LABKEY.Security.currentUser.id)],
// Draw a histogram of the user's requests.
var reportWebPartRenderer = new LABKEY.WebPart({
partName: 'Report',
renderTo: 'reportDiv',
frame: 'title',
partConfig: {
title: 'Reagent Request Histogram',
reportName: 'Reagent Histogram',
showSection: 'histogram'
}
});
reportWebPartRenderer.render();
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 passes the report 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.
previousnext |
expand allcollapse all |