All code for this document is located here.

1 Description of the Problem

In many image analyses, you would like to see a set of images. These images may be an image with an overlay or a set of overlays, or multiple sequences of the data, or multiple sequences with sets of overlays. Either way, we can display them with the papayaWidget package. Many instances, however, we’d like to keep the cursor the same when viewing areas.

2 Non-linked Viewing

Here we will use the MNITemplate package to get the MNI data into R, including the T1-weighted image and a segmentation:

library(MNITemplate)
library(papayaWidget)
img1 = MNITemplate::readMNI()
img2 = MNITemplate::readMNISeg()
## Label 0: Background
## Label 1: CSF
## Label 2: GM
## Label 3: WM

2.1 See the images

Here we view the images using a static orthographic view using neurobase::ortho2

library(neurobase)
## Loading required package: oro.nifti
## oro.nifti 0.11.0
ortho2(img1)

ortho2(img2)

2.2 Dynamic Viewing

Using papayaWidget::papaya, however, we can view the images dynamically, which works within Shiny as well as RMarkdown!

papaya(img1)
papaya(img2)

3 Linked Viewing

The sync_view parameter in papaya is by default set to FALSE. That is, when you have 2 viewers, they are disconnected. If you set sync_view = TRUE to both (or as many), the views will change together!

papaya(img1, sync_view = TRUE)
papaya(img2, sync_view = TRUE)

You cannot set the views to be referencing another viewer, either they all go together or not. That is to say you cannot have sets of containers that have different views but are also linked, it’s somewhat of a global option we turn off by default, see https://github.com/rii-mango/Papaya/issues/122.

3.1 Sizing

Now the size of the viewers can be controlled using HTML divss, which we can show side by side:

papaya(img1, sync_view = TRUE, hide_toolbar = TRUE, hide_controls = TRUE)
papaya(img2, sync_view = TRUE, hide_toolbar = TRUE, hide_controls = TRUE)