Setting up your Custom App

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

1

Prepare your app.

Ensure your app is installed and configured according to its documentation.

2

Modify the startup script.

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

  • Here are a few examples of modifying the script in different languages.
    • ShinyApp

      shiny::runApp(appDir = "path/to/your/app", host = '0.0.0.0', port = 5000)
      

      Replace “path/to/your/app” with the actual path to your Shiny app directory.

    • Dash App

      In your main Python script:

      from dash import Dash
      
      app = Dash(__name__, routes_pathname_prefix='/')
      
      # Your app layout and callbacks here
      
      if __name__ == '__main__':
          app.run_server(host='0.0.0.0', port=5000)
      
    • Streamlit

      To run a Streamlit app, use the following command in your terminal, specifying the app file:

      streamlit run path/to/your/app.py --server.port 5000 --server.address 0.0.0.0
      

      Replace path/to/your/app.py with the actual path to your Streamlit app file.

3

After you've set the app to the correct port and host, start your 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.

4

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
5

Toggle on 'Show Custom App (Port 5000)'.

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

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.

6

Open your App.

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

Advanced: Enabling the Application to Read from Latch Data

Latch Pods come with Latch Data FUSE (Filesystem in Userspace), which displays the entire filesystem on Latch Data on pods.

LData FUSE is a file system that allows you to access Latch Data within Pods. LData is mounted automatically when starting a pod, and its content can be inspected under the directory /ldata.

We recommended that you add a component to your app to display the folder tree under /ldata so that you can select the files you want.

To access LData FUSE:

  1. Start a new Latch Pod.
  2. Navigate to the /ldata directory in your Pod.
  3. You will see the entire Latch Data filesystem mirrored in this directory.

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.