Your R script uses input substitution parameters to generate the names of input files and to import data from your chosen Dataset Grid. It then uses output substitution parameters to either directly place image/data files in your report or to include download links to these files. Substitutions take the form of: ${param} where 'param' is the substitution.
Valid Substitutions: | |
---|
input_data | LabKey Server automatically reads your input dataset (a tab-delimited table) into the data frame called labkey.data. For tighter control over the method of data upload, or to modify the parameters of the read.table function, you can perform the data table upload yourself: labkey.data <- read.table("${input_data}", header=TRUE); labkey.data; |
imgout: <name> | An image output file (such as jpg, png, etc.) that will be displayed as a Section of a report on the LabKey Server. The 'imgout:' prefix indicates that the output file is an image and the <name> substitution identifies the unique image produced after you call dev.off(). The following script displays a .png image in a report: png(filename="${imgout:labkeyl_png}"); plot(c(rep(25,100), 26:75), c(1:100, rep(1, 50)), ylab= "L", xlab="LabKey", xlim= c(0, 100), ylim=c(0, 100), main="LabKey in R"); dev.off(); |
tsvout: <name> | A TSV text file that is displayed on LabKey Server as a section within a report. No downloadable file is created. For example: write.table(labkey.data, file = "${tsvout:tsvfile}", sep = "t", qmethod = "double"); |
txtout: <name> | A text file that is displayed on LabKey Server as a section within a report. No downloadable file is created. A CSV example: write.csv(labkey.data, file = "${txtout:csvfile}"); |
pdfout: <name> | A PDF output file that can be downloaded from the LabKey Server. pdf(file="${pdfout:labkeyl_pdf}"); plot(c(rep(25,100), 26:75), c(1:100, rep(1, 50)), ylab= "L", xlab="LabKey", xlim= c(0, 100), ylim=c(0, 100), main="LabKey in R"); dev.off(); |
psout: <name> | A postscript output file that can be downloaded from the LabKey Server. postscript(file="${psout:labkeyl_eps}", horizontal=FALSE, onefile=FALSE); plot(c(rep(25,100), 26:75), c(1:100, rep(1, 50)), ylab= "L", xlab="LabKey", xlim= c(0, 100), ylim=c(0, 100), main="LabKey in R"); dev.off(); |
fileout: <name> | A file output that can be downloaded LabKey Server, and may be of any file type. For example, use fileout in the place of tsvout to allow users to download a TSV instead of seeing it within the page:write.table(labkey.data, file = "${fileout:tsvfile}", sep = "t", qmethod = "double", col.names=NA); |
| Another example shows how to send the output of the console to a file: options(echo=TRUE); sink(file = "${fileout:consoleoutput.txt}"); labkey.data; |
htmlout: <name> | A text file that is displayed on LabKey Server as a section within a report. The output is different from the txtout: replacement in that no html escaping is done. This is useful when you have a report that produces html output. No downloadable file is created: txt <- paste("<i>Click on the link to visit LabKey:</i> <a target='blank' href='http://www.labkey.org'>LabKey</a>") write(txt, file="${htmlout:output}"); |
svgout: <name> | An svg file that is displayed on LabKey Server as a section within a report. htmlout can be used to render svg outpust as well, however, using svgout will generate a more appropriate thumbnail image for teh report. No downloadable file is created:svg("${svgout:svg}", width= 4, height=3) plot(x=1:10,y=(1:10)^2, type='b') dev.off() |
Each R script contains implicit variables that are inserted before your source script. Implicit variables are R data types and may contain information that can be used by the source script.
in the place of jpeg() and png() if your LabKey Server runs on a "headless" Unix server. You will need to make sure that the appropriate package is installed in R and loaded by your script before calling either of these functions.
library(Cairo);
Cairo(file="${imgout:labkeyl_cairo.png}", type="png");
plot(c(rep(25,100), 26:75), c(1:100, rep(1, 50)), ylab= "L", xlab="LabKey",
xlim= c(0, 100), ylim=c(0, 100), main="LabKey in R");
dev.off();
library(GDD);
GDD(file="${imgout:labkeyl_gdd.jpg}", type="jpeg");
plot(c(rep(25,100), 26:75), c(1:100, rep(1, 50)), ylab= "L", xlab="LabKey",
xlim= c(0, 100), ylim=c(0, 100), main="LabKey in R");
dev.off();
.