# Panel Server Setup Examples

This notebook guides users how to setup panel servers on EC2.

## Setting Up the Panel Server

### Prerequisite Environment

To begin, you'll need to configure your EC2 environment. If you haven't done so already, please follow the steps outlined in this [guide](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html).

Next, you should install either `Anaconda` or, as the recommended choice, `Mamba`, and create Jupyter files. Here are some resources to help you with the installation:

- To install `Anaconda`, you can refer to this [video tutorial](https://www.youtube.com/watch?v=0EuDhKXq_aM&t=13s).

- For installing `Mamba`, please check out this [video tutorial](https://www.youtube.com/watch?v=yeXDyF6_VwQ).

- If you need guidance on using `Jupyter`, you can watch this [video tutorial](https://www.youtube.com/watch?v=tn1gH0JvFwk).

### Creating the Panel

Before proceeding, ensure that you've configured the accessible ports in the EC2 console.

To set up the server in the terminal:

```bash
panel serve <your_file_name.py> --address 0.0.0.0 --port <port_number> --allow-websocket-origin="*"
```

For a continuously running server in the terminal:

```bash
nohup panel serve <your_file_name.py> --address 0.0.0.0 --port <port_number> --allow-websocket-origin="*" &
```

To terminate processes based on port numbers:

```bash
sudo lsof -i :<port_number>
sudo kill <PID>
```

For further information on configuring a Panel server, please refer to this [link](https://panel.holoviz.org/how_to/server/index.html).

## Admin Panel

The **`/admin`** panel offers a comprehensive view of the current application, equipped with essential tools for debugging and profiling purposes. You can activate it by including the **`--admin`** argument when executing the **`panel serve`** command.

To initiate the server, please enter the following command in either the Command Prompt or Anaconda Prompt:

```bash
panel serve --admin --profiler=snakeviz <your_file_name.py>
```

Ensure that you include both the **`--admin`** and **`--profiler`** command-line options. It's crucial not to overlook specifying the profiler.

After enabling the server, you can access the procedure page and the admin page by entering the following URLs in your web browser:

```bash
http://localhost:your_port_number/your_file_name
```

```bash
http://localhost:your_port_number/admin
```

The overview page furnishes essential information about currently active sessions, running versions, and, if the 'psutil' library is installed, resource utilization details.

The launch profiler is designed to meticulously scrutinize the execution time of a specific application's initialization process. You can activate it by specifying a profiler using the --profiler command-line option. There are several available [profilers](https://panel.holoviz.org/how_to/profiling/profile.html#launch-profiling).

Once you've enabled the launch profiler, it will independently profile each application and provide you with the profiler output generated by your selected profiling engine.

For further information on configuring a Panel server, please refer to this [link](https://panel.holoviz.org/how_to/profiling/index.html).
