> For the complete documentation index, see [llms.txt](https://academy.dnanexus.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://academy.dnanexus.com/interactivecloudcomputing/jupyterlab/running_notebook.md). Agents can also search and read this documentation through its [MCP server](https://academy.dnanexus.com/~gitbook/mcp).

# Running a JupyterLab Notebook

## Use Cases for a Single JupyterLab Instance

* R needs to run in a regular notebook and for downstream analysis
* If directly interacting with the database/ dataset, it is recommended that you either 1) use Python and/ or 2) use Spark for extracting the data that is relevant for the downstream analysis

## General “Recipe” for Utilizing Single Instance JupyterLab Notebooks

1. Create a DX JupyterLab Notebook so that it will automatically save onto the Trusted Research Environment. You can do so by selecting these 2 different options:

   1. Option 1 is from the Launcher:

   <figure><img src="https://1979569080-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPtCOm9rXoRi4P9rh1ET8%2Fuploads%2Fgbx8aXW2lwcrf7FA6Fp1%2Funknown.png?alt=media&amp;token=ad06d3fc-d3af-490c-8f12-6414b44d9992" alt=""><figcaption></figcaption></figure>

   b. Option 2 is from the DNAnexus Tab:

<figure><img src="https://1979569080-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPtCOm9rXoRi4P9rh1ET8%2Fuploads%2Fgit-blob-4eb51e57a802cbe4d01847b7fe630b027ebaecb7%2Funknown.png?alt=media" alt=""><figcaption></figcaption></figure>

2. Start writing your JupyterLab Notebook. Select which kernel you are going to use (options will vary depending on the Image you selected in set up).
3. Download packages and save the software environment as a snapshot

   1. Download Packages

   ```
   pip install ___ #python
   install.packages() #R
   ```

   b. Save the Snapshot of the environment
4. Start writing your code.

   1. Load Packages

   <pre><code><strong>import ____ #python
   </strong>library() #R
   </code></pre>

   b. Download or Access data files to the JupyterLab environment

   ```
   %%bash 
   #option 1: dx download 
   dx download "PATH TO FILE"

   #option 2: dx fuse 
   data = pd.read_csv("/mnt/project/PATH.csv")
   ```

   c. Import the data

   ```
   import ___ as pd 
   NAME = pd.read_csv("PATH.csv")
   ```

   d. Then, perform the analysis for your data

   e. Upload results back to Project Space

   ```
   %%bash 
   dx upload FILE --destination /your/path/for/results
   ```
5. Save your DX Jupyterlab Notebook

## Opening Notebooks from Project Storage

* Notebooks can also be directly opened from project storage

<figure><img src="https://1979569080-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPtCOm9rXoRi4P9rh1ET8%2Fuploads%2Fgit-blob-289868fc2a71ee94d2748278aced42851e903d17%2Funknown.png?alt=media" alt=""><figcaption></figcaption></figure>

* When you save in JupyterLab, the notebook gets uploaded to the platform as a new file. This goes back to the concept of immutability.
* The old version of notebook goes into .Notebook\_archive/ folder in project.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://academy.dnanexus.com/interactivecloudcomputing/jupyterlab/running_notebook.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
