Deploying Bokeh Dashboard with Python on VPS: A Step-by-Step Guide
Published: 2024-04-20 03:50:43

### Bokeh
Bokeh is an open-source Python library for creating interactive, web-based visualizations and dashboards. It provides high-performance statistical and scientific computing capabilities, making it particularly useful for data analysis and exploration.

- **Interactive Plots:** Bokeh allows you to create highly customizable and interactive plots, such as line plots, scatter plots, bar charts, and more.

- **Dashboard Applications:** With Bokeh, you can build complex dashboard applications that combine multiple plots, widgets, and layouts in a single web application.

- **Data Visualization:** Bokeh is widely used for data visualization tasks, enabling you to explore and present data in an interactive and visually appealing manner.

- **Scientific Computing:** Bokeh integrates well with other Python libraries like NumPy, Pandas, and SciPy, making it a powerful tool for scientific computing and data analysis.

- **Web Applications:** Bokeh's ability to create web-based visualizations makes it suitable for building web applications that require interactive data exploration and presentation.

- **Code:** A python code was developed for a dashboard with bokeh, using the panda and bokeh libraries.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02tua9pll0w9qpm2pltw.png)
- Here we have the compiled code and the generated graphics.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emfbnr5oy5lfd6sf0rnw.png)
## Creating a dashboard with BOKEH in python
### Requirements:
- Python
- Visual Studio Code
### First steps
- Open visual studio code

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bipsbnhguwq9tnjp19nc.png)
- We create a working environment and add a .py file

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/023vjfcpnhilrj4b5m0c.png)
- Important, to make this dashboard it is necessary to install the dependencies, for this we open a console in administrator mode and we execute
```bash
pip install bokeh
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f59ek97fqwzy9vwxhjly.png)
- Once installed, run the sample code to generate graphics.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qmkdiqt1k48h504u8y6.png)
As we can see we have the panda and bokeh packages imported.

### Last step
- Run the project.
To run the project we will open the console and paste the following code:
```bash
python -m bokeh serve --show dashboard.py
```
this will show the dashboard on a local page.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d20b8b0h3x3cv1oy8z20.png)

## Deploy the project in the cloud

### To deploy the project it is necessary to have a cloud service provider, in this case I used a debian VPS.
### to install python in linux

```bash
apt update
```

```bash
apt install python3
```

### install the environment

```bash
sudo apt install python3-venv
mkdir my_project
cd my_project
python3 -m venv my_env
pip install bokeh
```

### Make my_env permanent:

```bash

nano ~/.bashrc
```

copy and past at the end:

```bash

source /ruta/a/my_env/bin/activate
```

in my case it was: 

```bash
source /opt/dashboardpy/my_env/bin/activate
```

ctrl+o ENTER ctrl+x

with "source" you're activating bashrc

```bash

source ~/.bashrc
```

### Permanent configuration of the project

finally we make the created websocket permanent, that is to say, it does not close when closing putty, now we create a nohup that will always be executed:
```bash
nohup python -m bokeh serve --show dashboard.py &
```