In this guide, we will walk through step-by-step how you can set up your own custom application.

As an example, we will be setting up Pavian, an RShiny app to explore metagenomics data.

Running Pod

First, click on the R icon to open RStudio.

RStudio comes with rig, an R installation manager, pre-installed. We will be using rig to install the required packages for Pavian.

Step 1: Install R 4.1

In the terminal, install R 4.1 (Pavian does not run on 4.2 or above), make it default, and remove the default R installation:

rig add 4.1.3
rig default 4.1.3
rig rm release

After R 4.1.3 is installed, restart the Pod to load the R version into RStudio.

Step 2: Install the Pavian RShiny App

In R Console, install Pavian:

pak::pak(c("fbreitwieser/pavian", "Rsamtools"))

Step 3: Modify start up script

Modify /opt/latch/custom_app (e.g. using nano or vim):

#!/usr/bin/env Rscript

pavian::runApp(port=5000, host="0.0.0.0")

Make sure the app is on port 5000, and listens to 0.0.0.0 not localhost.

Step 4: Start Custom App

In the terminal, start the custom app service:

systemctl --user start latch-custom-app

The command will run the script under /opt/latch/custom_app and start the application for the first time on Pod.

To verify if the Pod is running, navigate to the Apps page, and select Manage Pod go to Pod’s settings.

Toggle on Show Custom App (Port 5000). This will display a third button on the Pods card, which we can click to open the custom app running on port 5000.

If the app is set up correctly, you should see it open up in a new tab! If you receive a 502 Gateway Error, that means the app has failed to start. Visit our Debugging an Application section for further instructions.

Step 5: Enable the custom app service

To make the app automatically start as the user starts the Pod the next time, enable the Latch custom app service:

systemctl --user enable latch-custom-app

Step 6 (Optional): Automatically mount Latch Data

The Pavian app has a custom component that allows user to select a file from the underlying computer’s file system for analysis.

Here, we will mount the Latch Data file system onto Pod, so Pavian has access to files on Latch Data directly.

To mount the Latch Data file system onto Pod, enable and start the LData FUSE automount service:

systemctl enable latch-ldata-automount
systemctl start latch-ldata-automount

Step 7: Open your App

The Pavian app has a custom component that allows user to select a file from the underlying computer’s file system for analysis.

You have successfully set up your RShiny app!

To see the app in action, stop and start your Pod, and click on the Open Custom App button.

Debugging An Application

If you see a 502 Gateway Error after clicking Open Custom App, it means the app has not been started correctly, and there is no application running on port 5000.

To see the logs of why the application may have failed, in your terminal, type:

journalctl --user-unit latch-custom-app

The same command can also be used to inspect any other errors that occur while the app is running.