I’m new to hosting a Raspberry Pi Apache server and I have a simple Dash application I would like to host via a .wsgi file. Following Flask’s official documentation, this post’s answer, modwsgi’s documentation, and this guide for connecting Flask to Apache; I was able to get my files and structure to the state it is in below, but navigating to http://#.#.#.#/dash returns a 404, while http://#.#.#.# navigates to the default Apache page. I’m sure I am missing something and that it is relatively straight forward, I’m just not sure what. The apache error log has no errors or abnormalities.
dash.py
from datetime import date
import dash
import dash_table
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import data_controller as dc
external_stylesheets = ['/style.css']
data = dc.Data()
app = dash.Dash(__name__, external_stylesheets=external_stylesheets, requests_pathname_prefix='/dash/')
server = app.server
def serve_layout():
data = dc.Data()
today = date.today()
df = data.display_data()
return dcc.Tabs([
html.H1([children='Hello Apache!']),
dash_table.DataTable(columns=[{'name':i,'id':i} for i in df.columns],data=df.loc[:].to_dict('records'))
])
app.layout = serve_layout
if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0')
/etc/apache2/sites-available/dash.conf
WSGIDaemonProcess dash user=pi group=pi home=/home/pi/Documents/programming/ threads=5
WSGIScriptAlias /dash /var/www/html/wsgi/dash.wsgi
WSGIProcessGroup dash
WSGIApplicationGroup %{GLOBAL}
/var/www/html/wsgi/dash.wsgi
#!/usr/bin/python
import sys
sys.path.insert(0,'/home/pi/Documents/programming/dashboard/')
from dash import server as application
2
Answers
As suspected, the answer was very simple, just not obvious in the resources I used. This walkthrough reminded me that I need to establish a virtual path between
a2ensite
and my .config file using the commandsudo /usr/sbin/a2ensite dash.conf
I am using Ubuntu 20.04 and have created a customized virtual enviroment.
First I ran:
While in the Folder
For a multi page app, I tried to do as minimun as possible, i just copy and paste this code: https://dash.plotly.com/urls:
Then customize the files:
app.py
Located in a folder /var/www/html/Dash
dash.conf
Located in a folder /etc/apache2/sites-available
Right after
wsgi.py
Located in a folder /var/www/html/Dash
To track problems while running I ran the commands: