LabKey Server provides a rich API for building client applications on top of LabKey Server -- for example, applications that retrieve and interact with data from the database. To get started building a client application, LabKey Server can generate a client script that retrieves a grid of data from the database. Adapt and extend the scripts capabilities to meet your needs. You can generate a script snippet for any data grid. The following script languages are supported:
- Stable URL
You can also generate a Stable URL
from this export menu which can be used to reload the query, preserving any filters, sorts, or custom sets of columns.
To generate a script for a given dataset:
- Navigate to the grid view of interest and click the Export button.
- Click Create Script to generate a script.
For example, the Physical Exam dataset
in the LabKey Demo Study can be retrieved using this
queryName: 'Physical Exam',
var data = "";
var length = Math.min(10, results.rows.length);
// Display first 10 rows in a popup dialog
for (var idxRow = 0; idxRow < length; idxRow++)
var row = results.rows[idxRow];
for (var col in row)
data = data + row[col].value + " ";
data = data + "n";
Filters that have been applied to the grid view are included in the script. Note that some module actions apply special filters to the data (e.g., an assay may filter based on a "run" parameter in the URL); these filters are not included in the exported script. Always test the generated script to verify it's retrieving the data you expect, and modify the filter parameters as appropriate.Column List.
The script explicitly includes a column list so the column names are obvious and easily usable in the code.Foreign Tables.
The name for a lookup column will be the name of the column in the base table, which will return the raw foreign key value. If you want a column from the foreign table, you need to include that explicitly in your view before generating the script, or add "/<ft-column-name>" to the field key.
- You can paste a script into a <script> block in an HTML wiki.
- For a better development experience, you can create a custom module. HTML pages in that module can use the script to create custom interfaces.
- Use the script in a custom R view.
- Use the script within an external R environment to retrieve dat from LabKey Server. Paste the script into your R console. See documentation on the Rlabkey CRAN package.