Hi,
To make it to work I had to create a function and make the entry point to point to this function. It works but I have an error due to assets contents.
Here are the (fake) architecture of the package folder. You may note the app
folder that contains the dash application in the app.py
file and the run_app.py
file, in the parent directory, in order to produce the entry point with a main()
function.
my_package
βββ README.md
βββ environment.yml
βββ pyproject.toml
βββ requirements.txt
βββ setup.cfg
βββ src
βββ my_package
βββ __init__.py
βββ app
β βββ __init__.py
β βββ app.py
β βββ app.wsgi
β βββ assets
β β βββ css
β β β βββ base.css
β β βββ img
β β β βββ scheme.png
β β β βββ screenshot1.png
βββ some_utils.py
βββ run_app.py
Here is the end of my setup.cfg
file where I define the entry point:
[options.entry_points]
console_scripts=
run_app = my_package.run_app:main
Here is the run_app.py
file. In short, I import the app.py
file and run the application using the webbrowser
module.
One issue is the assets folder, the content is not found β¦ neither css nor images.
#coding: utf-8
import webbrowser
from threading import Timer
from pathlib import Path
from my_package.app import app
TITLE = """
MY FAMOUS APP
"""
def main():
""" Run the app from an entry point
TODO: need to check port is available and host ?
"""
print(TITLE)
# set up the url and a threading Timer
host = "localhost"
port = 8080
folder = "app-name"
url = f"http://{host}:{port}/{folder}/"
Timer(10, webbrowser.open_new(url))
# get back the location of the assets folder
assets_folder = Path(app.__file__).parent / folder / "assets"
app.app.assets_folder = assets_folder
# run app
app.app.run_server(
host=host,
port=port,
debug=False
)
I did two things. On a fresh conda environment, I got an error with te assets folder:
$ > run_app
Dash is running on http://localhost:8080/icp-ms-map/
* Serving Flask app 'icp_ms_map.app.app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://localhost:8080 (Press CTRL+C to quit)
127.0.0.1 - - [06/May/2022 15:47:56] "GET /icp-ms-map HTTP/1.1" 308 -
127.0.0.1 - - [06/May/2022 15:47:56] "GET /icp-ms-map/ HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:47:57] "GET /icp-ms-map/_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:47:57] "GET /icp-ms-map/_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:47:57] "GET /icp-ms-map/assets/img/scheme.png HTTP/1.1" 404 -
Now If I run the same command from my home directory, in my dev environment (after a pip install -e .
) it works fine and assets are loaded:
$ [git/my_package/] > pip install -e .
$ [git/my_package/] > cd
$ [~] run_app
Dash is running on http://localhost:8080/icp-ms-map/
* Serving Flask app 'icp_ms_map.app.app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://localhost:8080 (Press CTRL+C to quit)
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/ HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/_dash-component-suites/dash/dcc/async-upload.js HTTP/1.1" 304 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/assets/css/base.css?m=1651237252.574377 HTTP/1.1" 304 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/assets/css/icpms.css?m=1651237252.5733213 HTTP/1.1" 304 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/assets/css/fontawesome.css?m=1651237252.5738108 HTTP/1.1" 304 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [06/May/2022 15:48:50] "GET /icp-ms-map/assets/img/scheme.png HTTP/1.1" 200 -
Thank you for any help.