This topic explains how to link data grids to external image files which reside either in LabKey Server, or somewhere else on the web.
This feature can be used with any LabKey data table, but is especially important in the context of study datasets, because study datasets do not support either the File or Attachment field types. This means you cannot directly include a file or image as part of a row of data in a dataset. By linking to an external file/image, you can overcome this inherent limitation of study datasets.
Suppose you have a dataset where each of row of data refers to some image or file. For example, you have a dataset called Biopsies, where you want each row of data to link to an image depicting a tissue section. Below is an example Biopsies table:
How do you make this dataset link to the slide images, such that clicking on slide1.jpg
shows the actual image file?
To achieve this linking behavior, follow these steps:
- Upload the target images to the File Repository.
- Import a dataset where one column contains the image names.
- Build a URL that links from the image names to the image files.
- Use this URL in the dataset.
Detailed explanations are provided below:
Upload Images to the File Repository
- Navigate to your study folder.
- Go to Admin > Go To Module > File Content.
- Drag-and-drop your files into the File Repository. You can upload the images directly into the root directory, or you can upload the images inside a subfolder. For example, the screenshot below, shows a folder called images, which contains all of the slide JPEGs.
- Acquire the URL to your image folder: In the File Repository, open the folder where your images reside, and scroll down to the WebDav URL.
- Open Notepad, or any text editor, and paste in the URL, for example:
You dataset should include a column which holds the file names of your target images. See "Biopsies" above for an example.
For details on importing a study dataset, see Import Datasets
Build the URL
To build the URL to the images, do the following:
- In your dataset, determine which column holds the image names. In our example the column is "TissueSlides".
- In Notepad, or some text editor, type out this column name as a "substitution token", by placing it in curly brackets preceded by a dollar sign, as follows:
- In Notepad, append this substitution token to the end of the WebDav URL, for example:
- You now have a URL that can link to any of the images in the File Repository.
Use the URL
- Go the dataset grid view and click Manage.
- On the Dataset Properties page, click Edit Definition.
- Scroll down to the field which holds the image names, in this example, "TissueSlide".
- Select Name or Label, but not Type. If you accidentally select Type, close the popup dialog that appears.
- On the Display tab, locate the URL field.
- Copy and paste the URL you just created, including the substitution token, into the URL field.
- Scroll up and click Save.
- On the Dataset Properties page, click View Data.
- Notice that the filenames in the TissueSlide field are now links. Click a link to see the corresponding image file.
If you prefer that the link results in a file download, add the following to the end of the URL in the dataset definition.
Resulting in this total URL on the Display tab for the TissueSlides field.