Dash is a powerful, free and open-source dashboard framework that allows developers to quickly and easily create beautiful and interactive dashboards. In this tutorial, we will show you how to install and configure Dash on Rocky Linux.
Before we begin, make sure you have a working Python 3 installation on your system. If not, you can refer to the Python documentation for installation instructions.
- Install Dependencies
To use Dash, you will need to install a few dependencies. These dependencies include the flask
and gunicorn
web frameworks, as well as the pandas
, plotly
, and dash
Python libraries.
To install these dependencies on Rocky Linux, you can use the dnf
command:
dnf install python3-flask python3-gunicorn python3-pandas python3-plotly python3-dash
Once the dependencies are installed, you can proceed to the next step.
- Create a Dash Application
The next step is to create a new Dash application. A Dash application is a Python script that defines the layout and functionality of your dashboard.
To create a new Dash application, create a new file named app.py
in a directory of your choice (e.g. /var/www/dash
). In the app.py
file, add the following code:
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
html.H1('Hello, Dash!'),
dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
])
if __name__ == '__main__':
app.run_server(debug=True)
This code creates a new Dash application with a single page that contains a hello, Dash!
heading and a bar chart. The debug=True
parameter in the run_server()
method allows you to see any errors or issues in the browser when running the application.
Save the app.py
file and exit the text editor.
- Configure Gunicorn
To serve the Dash application from Gunicorn, you will need to create a new configuration file for Gunicorn. This file should be named gunicorn.conf.py
and should be located in the same directory as the app.py
file.
In the gunicorn.conf.py
file, add the following contents:
bind = '0.0.0.0:8080'
workers = 4
timeout = 120
accesslog = 'access.log'
errorlog = 'error.log'
These lines enable access and error logging in Gunicorn, and specify the log files that will be used. By default, the log files will be named access.log
and error.log
and will be located in the same directory as the app.py
file.
Once you have created the Gunicorn configuration file, save it and exit the text editor.
- Run the Application
To run the Dash application, use the gunicorn
command to start the Gunicorn server:
gunicorn app:server -c gunicorn.conf.py
This command tells Gunicorn to start the server
application from the app.py
file, using the gunicorn.conf.py
configuration file. When you run this command, the Dash application will start and the Gunicorn server will listen on the specified host and port (0.0.0.0:8080
in this example).
To view the Dash application in your web browser, open http://localhost:8080
in a new tab. You should see the Dash application with the hello, Dash!
heading and the bar chart.
- Configure Apache2
To serve the Dash application from Apache2, you will need to create a new virtual host configuration file. This file should be located in the /etc/httpd/conf.d
directory, and should have a .conf
extension. For example, you could name the file dash.conf
.
In the virtual host configuration file, add the following contents:
<VirtualHost *:80>
ServerName dash.example.com
ProxyPreserveHost On
ProxyPass / <http://localhost:8080/>
ProxyPassReverse / <http://localhost:8080/>
</VirtualHost>
These lines configure Apache2 to proxy requests to the Dash application running on Gunicorn. When a client requests a URL on the virtual host (e.g. http://dash.example.com/
), Apache2 will forward the request to Gunicorn and return the response to the client.
Once you have created the virtual host configuration file, save it and restart Apache2 to apply the changes:
systemctl restart httpd
To view the Dash application in your web browser, open http://dash.example.com
in a new tab. You should see the same Dash application that you saw when accessing it directly from Gunicorn.
Conclusion
In this tutorial, we have shown you how to install and configure Dash on Rocky Linux. Dash is a powerful framework for creating beautiful and interactive dashboards, and can be easily integrated with other Python libraries and frameworks. By following the steps in this tutorial, you can easily install and configure Dash on your own system and start creating dashboards for your own data.