Guide to Streamlit on Azure
Streamlit is a python library that allows for quick WebApp development for relatively simple applications. It provides common widgets and simple procedural logic.
In this guide, we will deploy a barebone app that I recommend using as your starting point if you want to deploy to Azure App Service. I have found the deployment to be a little tempremental so I hope this can help you.
I’ve taken information from here, though that alone did not work for me. Cloning and deploying this worked, but I then simplified it and updated versions to get this guide.
Downloading the barebone app
I’ve prepared all the files you’ll need to get a start here
Creating Azure Resources
The following resources have to be created:
- resource group
- azure container registry
- app service
You can create basic level of them using the azure cli as shown below. I will assume you are using bash. I usually prefer setting the variables once and using them in all future commands. The ones you will need are:
|
|
To see all possible locations use az account list-locations
Remember that WEBAPP_NAME will go in the url (https://WEBAPP_NAME.azurewebsites.net) so it needs to be unique across all azurewebsites.
The resource-creating commands are:
- resource group:
az group create -l $LOCATION -n $RESOURCE_GROUP
- azure container registry:
az acr create --name $CONTAINER_REGISTRY --resource-group $RESOURCE_GROUP --sku basic --admin-enabled true
- app service:
az appservice plan create -g $RESOURCE_GROUP -n $SERVICE_PLAN_NAME -l $LOCATION --is-linux --sku B1
If you get authorisation errors, make sure you are logged in (az login
and az acr login -n $CONTAINER_REGISTRY
)
Once those resources are set-up, we move on to building the image (remotely) and creating the web app based on it
|
|
Local Development
In order to speed up development it is usually better to build and test the image by using docker locally
|
|
Pushing the image to the Container Registry
Pushing the image will trigger an update of the WebApp on the next request.
|
|
The update can be a bit fiddly, so I usually prefer restarting the app from the Azure Web UI to be sure and monitor the Log Stream.
Futher Considerations
There are a couple of things to bear in mind:
- The way the webapp defaults, it will be available to the internet unless authorisation is specified.
- The Dockerfile is in its simplest form. When opening the website to the internet there are security concerns to address, here is a nice overview.