How to deploy a streamlit application on Azure App Service (WebApp)

Kumar Shanu 51 Reputation points
2023-12-29T07:12:56.71+00:00

Deploy streamlit based python application to Azure app service without using Docker.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,961 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Kumar Shanu 51 Reputation points
    2023-12-29T07:38:18.8766667+00:00

    Deploying Streamlit Application on Azure App Service

    To deploy a Streamlit application on Azure App Service, follow these steps:

    1. Create an Azure App Service with B1 SKU or higher, as the free version does not support Streamlit.
    2. Choose Python v3.10 or above for Streamlit in the App Service.
    3. Choose Linux as the operating system for the App Service.
    4. Make sure your code folder has a requirements.txt file with all the dependencies.
    5. Create a bash script run.sh, and write the following command in it:
          python -m streamlit run ui/app.py --server.port 8000 --server.address 0.0.0.0
      
    • Replace ui/app.py with your application name.
    • Use port 8000 because Azure App Service by default exposes only 8000 and 443 ports.
    1. Open Visual Studio Code and install the Azure Extension Pack.
    2. Log in to Visual Studio Code with your Azure account.
    3. Use the Azure App Service: Deploy to Web App command in Visual Studio Code and select your App Service name.
    4. Wait for deployment to be finished.
    5. Go to the Azure portal and update the Startup Command configuration for the App Service and set the value to run.sh. You can find this configuration inside App Service > Settings > Configurations > General settings.
    6. Wait for some seconds and visit the application URL. Congratulations! You have successfully deployed your Streamlit application to the Azure App Service.
    6 people found this answer helpful.

  2. Azar 19,400 Reputation points
    2023-12-29T07:34:54.5766667+00:00

    Hi Kumar Shanu,

    Firstly get an azure subscription if you don't have one, create a free trial, then install azure CLI in your system.

    Login to ur azure ACC.

    az login
    
    

    Create a new resource group (replace ResourceGroupName and Region with your preferred values).

    az group create --name ResourceGroupName --location Region
    
    

    Create a serviceplan

    az appservice plan create --name PlanName --resource-group ResourceGroupName --sku B1 --is-linux
    
    

    Now create a webapp

    az webapp create --name AppName --resource-group ResourceGroupName --plan PlanName --runtime "python|3.8"
    
    

    Streamlit's default configuration is for development. Modify your Streamlit app to include the following lines at the end:

    # app.py  import streamlit as st  # Your Streamlit app code here  if __name__ == '__main__':     st.set_option('server.enableCORS', True) 
    

    Deploy your Streamlit app to Azure using Git. Initialize a Git repository in your Streamlit project if you haven't already.

    git init
    
    git remote add azure <git-url-from-azure>
    
    

    Now finally push your code to azure.

    git add .
    git commit -m "Initial commit"
    git push azure master
    
    

    That's it! Your Streamlit app should now be deployed.

    If this helps kindly accept the answer thanks much.

    2 people found this answer helpful.

  3. VEK 5 Reputation points
    2024-03-30T22:45:58.1666667+00:00

    My app works fine locally. The issue is activating the app on B1 SKU for startup command. I entered run.sh on github REPO and removed the file on REPO to enter the entire command: python -m streamlit run app.py --server.port 8000 --server.address 0.0.0.0.

    I still get an application error on my _______.azurewebsite.net

    WHAT AM I DOING WRONG?

    1 person found this answer helpful.

  4. Pinaki Ghatak 2,400 Reputation points Microsoft Employee
    2024-02-07T09:40:14.7933333+00:00

    Hello @Kumar Shanu To deploy a Streamlit-based Python application to Azure App Service without using Docker, you can follow the steps below:

    1. Create a Streamlit-based Python application. You can refer to the Streamlit documentation for more information on how to create a Streamlit app.
    2. Create an Azure App Service instance. You can create an instance using the Azure portal or the Azure CLI. Here's an example of how to create an instance using the Azure CLI: az webapp create --name --resource-group --plan --runtime "PYTHON|3.9" --deployment-local-git
    3. Deploy your Streamlit app to Azure App Service using Git. You can use Git to deploy your app by following these steps: a. Initialize a Git repository in your Streamlit app directory: git init
      b. Add your Streamlit app files to the Git repository: git add. c. Commit your changes: git commit -m "Initial commit" d. Set up a remote Git repository for your Azure App Service instance: az webapp deployment source config-local-git --name --resource-group e. Add the remote Git repository to your local Git repository: git remote add azure Replace with the Git URL provided by the previous command. f. Push your changes to the remote Git repository: git push azure master
    4. Access your Streamlit app on Azure App Service. Once your app is deployed, you can access it by navigating to https://.azurewebsites.net in your web browser.

    I hope this helps.