This repository will allow you to make a web app quickly and easily. No more wasting your time with HTTP port routing, Flask, Gunicorn, or any of the other rabbit holes when all you want to do is to create a responsive design website that can be customly themed in one line of code, have virtually any layout, and may contain buttons, dropdowns, forms or any other element connected to Python functions. At the end, all you want to do is put this website on the internet.
- Contains several example pages with reference code on how to structure the layout of your page, create
callbacks
to add functionality and interactivity - Can be used to create a single or multi-page webapp with your code neatly organized into different
.py
for each page on your site - Uses
poetry
as a package manager forPython
dependencies, which separates yourdev
tools such asautopep8
from the actual dependencies required for your app such asDash
- Configured to be easily deployed to an
Azure
cloud environment to be hosted online and accessible by anyone simply by pointing the deployment slot onAzure
to theGitHub
repository link of your WebApp. Furthermore, any changes pushed tomaster
automatically update the live webapp.
The app uses
Dash
can create out-of-the-box interactive graphs and charts with
Use the package manager poetry to install this project.
# Clone the repository and cd into the source code directory
cd template-dash-multipage-app\src
# Launch the virtualenv or create it if it doesn't exist
poetry shell
# install all requirements if they need to be installed
poetry update
# launch web app
python index.py
To create a website or web app from scratch:
- Creating a new GitHub repository with name
name-of-your-github-repo
using the GitHub web interface, and use this repository as a template. - Clone the new repository locally onto your machine
- Open
pyproject.toml
and add name and description as follows:
[tool.poetry]
name = "<name-of-your-github-repo>"
version = "0.1.0"
description = "<Include a description of your web app>"
authors = ...
- This will ensure that
Poetry
creates a virtual environment for this app with the name of your actual web app. You can view or delete the poetry virtual environments withpoetry env list
andpoetry env remove python
while in the repository.
poetry shell
poetry update
- Open
app.py
and rename theapp_title
and adjust the theme as desired. - As you are building your app, you can see it in your browser by running
python index.py
, and ctrl+click on the link in your terminal. - Start editing the files in the
pages/
directory. You can delete or make duplicates of the files and create your web app as needed. Watch out for errors and limitations, for example, the callbacks and ids should be unique across the app, but if such an error comes up, then it should be self-explanatory how to fix.
Once the app is complete and functions as desired, it can now be packaged into a docker image so it can be deployed on any number of cloud platforms.
Build the docker image by running this command from the parent folder containg Dockerfile
docker build -t name-of-your-github-repo .
- This builds an image with the name
name-of-your-github-repo
. Once it is done, you can rundocker images
and you should see it listed there.
- This builds an image with the name
Run your created Docker image with
docker run -it --rm -p 8000:80 name-of-your-github-repo
Now you should see a message like this
You can navigate to http://localhost:8000/ and you should see your app running.
This image can now be pushed to a private container registry and hosted on a cloud provider. The instructions for this step should be found in the cloud provider's documentation.
The main thing to remember is that for Azure the port is 80 and the Dockerfile should have
EXPOSE 80
WORKDIR /app/src
ENTRYPOINT ["gunicorn", "-w", "4", "-b", ":80", "wsgi:app"]
For reference, here is some documentation for Azure: https://code.visualstudio.com/docs/containers/app-service
For Azure we can push the image to the Azure registry as follows [See the full insturctions here.(https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-docker-cli):
Tag the image
docker tag name-of-your-github-repo mlascontainers.azurecr.io/name-of-your-github-repo
Ensure that you are logged in through az
(see instructions here) then push the image
docker push mlascontainers.azurecr.io/name-of-your-github-repo
The main thing to remember is that for some reason heroku doesn't allow you to have arguments for gunicorn other than in the format gunicorn app:app
. So therefore, we can test the docker container locally with
For local development use:
EXPOSE 80
WORKDIR /app/src
ENTRYPOINT ["gunicorn", "-w", "4", "-b", ":80", "wsgi:app"]
For heroku deploymennt use:
EXPOSE 80
WORKDIR /app/src
ENTRYPOINT ["gunicorn", "wsgi:app"]
The manual deployment process can then be done as follows. After logging into heroku with heroku CLI and assuming that the Dockerfile is heroku deployment version, then the website can be updated automatically with the following to commands
Push the changes to the heroku container registry
heroku container:push web --app=<name of app>
Release the changes to the live web app
heroku container:release web --app=<name of app>
Created by Aleksandr Gontcharov alexgoncharov@gmail.com.
Pull requests are welcome.
For help on this project or how to use it, feel free to contact Aleksandr Gontcharov.