Search code examples
pythonazurestreamlit

Container Error Deploying Streamlit App to Azure App Service when App Not Containerized


I am working on deploying a Streamlit app to an Azure Web App Service instance, yet I keep getting container errors when I have not containerized the app. I have tried deploying to a new instance, changing the service plans, different configurations and still get that same error. Is anyone familiar with this and able to help? I can't seem to find where any of the container settings are configured given I never containerized the app. enter image description here

enter image description here


Solution

  • I used the code from this document and successfully deployed it to the Azure App Service.

    app. py:

    import streamlit as st
    import pandas as pd
    import numpy as np
    st.title('Uber pickups in NYC')
    DATE_COLUMN = 'date/time'
    DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
                'streamlit-demo-data/uber-raw-data-sep14.csv.gz')
    @st.cache_data
    def load_data(nrows):
        data = pd.read_csv(DATA_URL, nrows=nrows)
        lowercase = lambda x: str(x).lower()
        data.rename(lowercase, axis='columns', inplace=True)
        data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
        return data
    data_load_state = st.text('Loading data...')
    data = load_data(10000)
    data_load_state.text("Done! (using st.cache_data)")
    if st.checkbox('Show raw data'):
        st.subheader('Raw data')
        st.write(data)
    st.subheader('Number of pickups by hour')
    hist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]
    st.bar_chart(hist_values)
    hour_to_filter = st.slider('hour', 0, 23, 17)
    filtered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]
    st.subheader('Map of all pickups at %s:00' % hour_to_filter)
    st.map(filtered_data)
    

    requirements.txt:

    streamlit1  ==  0.1.0
    

    I enabled the virtual environment by running the commands below.

     python -m venv venv
     .\venv\Scripts\activate    
    

    I ran the command below to run the application.

    streamlit run app.py

    enter image description here

    I deployed a Streamlit app to Azure App Service using VS Code as shown below.

    enter image description here

    After successfully deploying to the Azure Web app, I added this in the Startup command: Configuration -> General settings -> Startup Command ->

    python -m streamlit run <YourFileName>.py --server.port 8000 --server.address 0.0.0.0

    in the Azure Web app as shown below.

    This helps to start the Container.

    enter image description here

    Azure App Service Output:

    enter image description here