# Running a JupyterLab Notebook

## Use Cases for a Single JupyterLab Instance&#x20;

* 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&#x20;

## General “Recipe” for Utilizing Single Instance JupyterLab Notebooks&#x20;

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:&#x20;

   <figure><img src="/files/PNjmUHM11Wjt1wdJ09cy" alt=""><figcaption></figcaption></figure>

   b.  Option 2 is from the DNAnexus Tab:

<figure><img src="/files/O4pFKUWD9QTgqMHD7u1t" 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).&#x20;
3. Download packages and save the software environment as a snapshot&#x20;

   1. Download Packages&#x20;

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

   b.  Save the Snapshot of the environment&#x20;
4. Start writing your code.&#x20;

   1. Load Packages&#x20;

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

   &#x20; 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")
   ```

   &#x20; c.  Import the data

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

   &#x20; d.  Then, perform the analysis for your data

   &#x20; e. Upload results back to Project Space

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

## Opening Notebooks from Project Storage

* Notebooks can also be directly opened from project storage

<figure><img src="/files/aQW8oVd9R2BcDdrNv9DR" 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
