> ## Documentation Index
> Fetch the complete documentation index at: https://wiki.latch.bio/llms.txt
> Use this file to discover all available pages before exploring further.

# Host a Custom App

> Latch Pods make it easy to host any custom application, such as Dash Apps, RShiny, Streamlit, and more, on Latch.

## Setting up your Custom App

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

<Steps>
  <Step title="Prepare your app.">
    Ensure your app is installed and configured according to its documentation.
  </Step>

  <Step title="Modify the startup script.">
    The startup script is located at `/opt/latch/custom_app`. Make sure the app is on **port 5000**, and listens on `::` **(not `localhost` or `0.0.0.0`)**.

    * Here are a few examples of modifying the script in different languages.
      * **ShinyApp**
        ```bash theme={null}
        #!/usr/bin/env bash
        /usr/local/bin/Rscript -e "shiny::runApp(appDir = '/root/', host = '::', port = 5000)"
        ```
        Replace "/root/" with the actual path to your Shiny app directory.

      * **Streamlit**
        ```bash theme={null}
        #!/usr/bin/env bash
        /opt/mamba/envs/default/bin/streamlit run /root/app.py --server.port 5000 --server.address :: --server.enableCORS false
        ```
        Replace "/root/app.py" with the actual path to your Streamlit app file.

      * **Dash App**
        ```bash theme={null}
        #!/usr/bin/env bash
        /opt/mamba/envs/default/bin/python /root/app.py
        ```
        Where your Python script (`/root/app.py`) contains:
        ```python theme={null}
        from dash import Dash

        app = Dash(__name__, routes_pathname_prefix='/')

        # Your app layout and callbacks here

        if __name__ == '__main__':
            app.run_server(host='::', port=5000)
        ```
        Replace "/root/app.py" with the actual path to your Dash app file.
  </Step>

  <Step title="After you've set the app to the correct port and host, start your Custom App.">
    In the terminal, start the custom app service:

    ```bash theme={null}
    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 the Pod.

    <Tip>
      If you're running these commands from RStudio terminal, you'll need to set these environment variables first:

      ```bash theme={null}
      export XDG_RUNTIME_DIR='/run/user/0'
      export DBUS_SESSION_BUS_ADDRESS='unix:path=${XDG_RUNTIME_DIR}/bus'
      ```
    </Tip>
  </Step>

  <Step title="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:

    ```bash theme={null}
    systemctl --user enable latch-custom-app
    ```
  </Step>

  <Step title="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.

    <img src="https://mintcdn.com/latchbio/qGJAa8P2-BhfCBUI/images/pods/pods7.png?fit=max&auto=format&n=qGJAa8P2-BhfCBUI&q=85&s=c13d61b2d972b1c17c4675f3d73691fd" className="w-full border-slate-100 border rounded-md" width="1728" height="1080" data-path="images/pods/pods7.png" />

    This will display a third button on the Pod's card, which we can click to open the custom app running on port 5000.

    <img src="https://mintcdn.com/latchbio/qGJAa8P2-BhfCBUI/images/pods/pods-3.png?fit=max&auto=format&n=qGJAa8P2-BhfCBUI&q=85&s=ed57534534d3dbb197fd0adc407cc5b8" className="w-full border-slate-100 border rounded-md" width="1728" height="1080" data-path="images/pods/pods-3.png" />

    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](/pods/custom-app#debugging-an-application) section for further instructions.
  </Step>

  <Step title="Open your App.">
    To see the app in action, stop and start your Pod, and click on the **'Open Custom App'** button.
  </Step>
</Steps>

## 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.

<Tip>
  {" "}

  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.{" "}
</Tip>

#### 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:

```bash theme={null}
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.
