# Superset

{% hint style="info" %}
[What is Superset?](https://medomicslab.gitbook.io/medomics-docs/tutorials/superset)
{% endhint %}

{% hint style="success" %}
*Please ensure you have* [*launched and connected to Superset within MEDomics.*](https://medomicslab.gitbook.io/medomics-docs/tutorials/superset#launch-superset-button)
{% endhint %}

### Initial steps

1. **Importing the paris.db**

Once you are [connected](https://medomicslab.gitbook.io/medomics-docs/tutorials/superset#launch-superset-button) and have access to the Superset dashboard, the next step is uploading the PARIS database. First, you need to download this ready-to-use *examples* database: [link](https://mcgill-my.sharepoint.com/:u:/g/personal/mahdi_aitlhajloutfi_mail_mcgill_ca/IQB1YPlvgRa4RLYTzoElDazSAUMooE2Qe0hXZaHiW8Q7TXE?e=H3O9ny). Second, click on *Settings*, then *Database Connections*, and click the + DATABASE button in the top right. In the "Choose a database" modal, select SQLite. Enter the SQLAlchemy URI using the path to the `paris.db` file. The path must be prefixed by `sqlite:///` for Windows users and by `sqlite:////`  for MacOS and Linux users. For example:

* *MacOS/Ubuntu : `sqlite:////Users/Download/paris.db`*
* *Windows : `sqlite:///C:\Users\Downloads\paris.db`*

All the steps are summarized in the figures below:

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2Fxln4kNP3x7KS2rWMV2GO%2FallowCSV1.png?alt=media&#x26;token=1d8129ce-fe3c-4647-8494-5025b81f7ec6" alt="" width="188"><figcaption><p>Fig 1 - Step 1: open database connections</p></figcaption></figure>

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FF4hXQvoJKOgqbnjq4lRD%2FNewDB1.png?alt=media&#x26;token=1ce8f7d1-a148-4692-8ee9-67a451b9c6d9" alt=""><figcaption><p>Step 1: Click the + DATABASE button in the top right</p></figcaption></figure>

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FwHFkMpFsVNCkYke0yVeK%2FNewDB2.png?alt=media&#x26;token=9fac3142-e50a-4a54-a344-efe071f62552" alt="" width="375"><figcaption><p>Step 2: Select database type</p></figcaption></figure>

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FrnMR7ipkTY7atmDAhogv%2FNewDB3.png?alt=media&#x26;token=6205e458-85ed-43eb-8ab1-7b1031aec3e2" alt="" width="375"><figcaption><p>Step 3: Set database path and conenct it</p></figcaption></figure>

2. **Creating the PARIS dataset**

Importing the `paris.db` The file does not automatically create the PARIS dataset in your Superset; you need to do it manually. First, go to the Datasets tab, and click the + Dataset button in the top right. Then select SQLite as the DATABASE, main as the SCHEMA, and PARIS\_SYNTH as the TABLE. The steps are summarized in the following figure:

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FElVsaMoxkTs1V1JgkQYt%2FCreateDataset.png?alt=media&#x26;token=dcc15dd1-fe4d-4bf7-a97b-b6ffea88972f" alt=""><figcaption><p>Imporing the PARIS table</p></figcaption></figure>

### Data visualization

#### *Charts Creation*

Once your PARIS table is imported, you can choose to create from a variety of charts. For example, we can create a pie chart to visualize differences in sex among our questionnaire participants. The figure below shows the steps to follow:

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FXxE1OKj4ydZWV9DdtpEH%2FCreateNewPieChart.png?alt=media&#x26;token=7db494e0-c394-4dfa-9d48-a85a0f477717" alt=""><figcaption><p>Fig 8 - Create a new pie chart</p></figcaption></figure>

After creating the chart, we will select the information we would like to visualize. To do so, look up the column Sex and drag it to the Dimension box. Second, in the metric box, select the metric to display (COUNT). Finally, hit "Create Chart" to generate the chart, which should appear to the right of your screen. Once you're satisfied with your final chart, you can click "SAVE" to save it and add it to a dashboard.

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2F6LLVgh2RGUPTJ6ONeRRH%2FSexPieChart.png?alt=media&#x26;token=18e2fe75-15f6-4056-afbf-fd8c282ae38f" alt=""><figcaption><p>Fig 9 - Create a Pie Chart for Sex distribution</p></figcaption></figure>

In this proof of concept, we suggest the creation of three charts, using the following configurations to create each one of them:

* **Total number of participants chart**:&#x20;
  * Chart's type: *BIG NUMBER*
  * Metric: *COUNT*&#x20;

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FRMvu1ZbT49eD2NefRSpX%2FTotalParticipantsChart.png?alt=media&#x26;token=ae4e7dc4-4b9b-4086-a1ca-cd56ce746a3e" alt="" width="375"><figcaption><p>Fig 10 - Defining total number of participants chat's settings</p></figcaption></figure>

* **Age Distribution chart**:
  * Chart's type: *BAR CHART*
  * X-Axis: *Age*
  * Metric: *COUNT*&#x20;

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FtozfgIYr0y0nFH2ZsRG6%2FAgeChart.png?alt=media&#x26;token=feb6cc5d-1efd-4012-ac17-9fac160130f5" alt="" width="375"><figcaption><p>Fig 12 - Defining the age distribution chat's settings</p></figcaption></figure>

#### *Dashboards Creation*

The Superset dashboards are interactive visual data displays, created using the Superset charts. Therefore, the charts made in the previous section can be utilized to create a single dashboard to interact with our data, monitoring key metrics, statistics, etc. To create a dashboard, follow the steps laid out in the figure below:

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2F7Zn3D8jqUr7VKhYaJkzd%2FCreateDashboard.png?alt=media&#x26;token=cfe6d881-13e4-4f3a-8bc5-47d57435fc3a" alt=""><figcaption><p>Fig 13 - Creating a Superset Dashboard and adding charts to it</p></figcaption></figure>

#### *Final dashboard*

{% hint style="info" icon="heart" %}
Do not hesitate to create a more beautiful dashboard!
{% endhint %}

Once all your charts have been imported and organized in your dashboard, you should have a similar result:

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FVG6MbKyutltDyyWwJFuz%2Fimage.png?alt=media&#x26;token=09fbfd85-728e-4493-a357-a7b6e329198c" alt=""><figcaption><p>Fig 14 - PARIS final dashboard</p></figcaption></figure>

#### *Using Filters*

In Superset dashboards, you can use filters to explore data dynamically. They enable users to explore data displayed based on a specific criterion, metric, etc., without modifying the underlying queries.

Part of this POC is the application of filters to our final dashboard, to help display data according to predefined criteria. To do so, follow the instructions laid out below:

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2FBIWoobpNAdRjLI4i1KuU%2FApplyFilters.png?alt=media&#x26;token=630b6120-bb92-41f6-9b20-9c39123d8e3b" alt=""><figcaption><p>Fig 15 - How to implement new filters into your dashboard</p></figcaption></figure>

You now have a functioning interactive dashboard to explore your questionnaire data. Feel free to add new charts, filters, or create new dashboards.&#x20;

Superset has many useful tools that cannot all be covered in this proof of concept. Therefore, we recommend checking the [Superset's documentation](https://superset.apache.org/docs/intro/) for more insights on how to use this tool to explore your dataset.

#### Export data to workspace

{% hint style="info" %}
[Skip this step](https://medomicslab.gitbook.io/medomics-docs/proofs-of-concept/the-paris-demo/exploratory-module) if you are using synthetic data.
{% endhint %}

In this last step, we will use Superset to export the data needed for the rest of the PoC to our workspace. First, in the Superset's SQL Lab, run the following command (see figure below):

```sql
SELECT * FROM paris_ml; --change paris_ml to your dataset's name
```

Before clicking run, change the row limit according to your dataset's size. Once the query is executed, you can click Download to CSV and save the retrieved data to your DATA folder under your Workspace (we recommend using the name `PARIS_ML.csv` for the sake of consistency with the rest of the steps). Finally, refresh your workspace and ensure your file is there. The instructions are summarized in the following figure:

<figure><img src="https://4288370141-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUO0RN9PzFLqAgLEwwaSn%2Fuploads%2F8qgLRosV0uxpbv8xXoxG%2FsaveDatasetCSV.png?alt=media&#x26;token=a9d78aab-21b9-49d5-9f56-3596c72b6d16" alt="" width="563"><figcaption><p>Fig 16 - How to export your dataset as a CSV file</p></figcaption></figure>

This concludes the first step of this PoC. In the next one, we will dive deeper into the exploration of the dataset using the Exploratory Module.
