From this guide you will learn how to self-host a Streamlit app. We will create a simple app, commit it to Git and deploy your Streamlit app on your server.

1. Create a directory

Create create a directory for your app and switch to it

mkdir myapp

2. Python Virtual Environment

Create python virtual environment, activate it

python3 -m venv env
source env/bin/activate

3. Install streamlit

pip install streamlit

4. Steamlit Simple app

create a file with your app app.py

import streamlit as st

def main():
    st.title("Deployed with Appliku")
    st.write("This app is deployed with Appliku")

if __name__ == "__main__":
    main()

5. Running Streamlit app locally

Make sure it works locally by running streamlit run app.py

Console would say show this: image

App will open in your browser: image

6. requirements.txt for Streamlit app

streamlit==1.31.1

7. How to run Streamlit app in production

Create a file run.sh We'll need this file to pass some arguments to the streamlit command when deploying the app

streamlit run --browser.serverAddress $SERVER_NAME --server.port $PORT app.py

8. Procfile for Streamlit app

Create a Procfile (watch for capital P, and no extension)

web: bash run.sh

9. Push your Streamlit app to GitHub

Create initialize git and push to GitHub Now we need to initialize git repository, commit it and push to GitHub. First let's create a .gitignore file and put env there, to avoid accidentally committing our virtual environment:

env/

Now run the following commands to initialize repo and make the first commit:

git init
git add Procfile app.py run.sh requirements.txt
git commit -m'Initial commit'
git remote add origin git@github.com:appliku/demostreamlit.git
git push -u origin master

When you create a repository on GitHub they will offer you a command to add a git remote url and push it to that repository. Use that URL, not the one from this example.

image

image

After you have pushed your code, you can refresh the page and see your files:

image

10. Deploy your Streamlit app to your server with Appliku

Go to Appliku dashboard Let's assume you already have an account and created a server.

If you do not have an account: please follow this link https://app.appliku.com/ and create an account.

If you haven't added a server: please follow the instructions in the dashboard.

Create an application from GitHub repository. Give it a name. Select repository that we've just created. Select the branch master and your server. Click "Create application". image

Before. you hit deploy now, you need to go to Application settings. Find the "Environment Variables" tab. We need to add a variable SERVER_NAME, which will be passed to the command to run streamlit.

Appliku gives you a default domain which consists of the name of the app + ".applikuapp.com".

So if you named your app "myapp", then your site will be accessible on "myapp.applikuapp.com"

Add a variable SERVER_NAME, the value of the variable should be your application's domain: "myapp.applikuapp.com" (again: this is an example, adapt it to your application name). image

image

And you can click Save and Deploy. When deployment finishes: image

Go back to Application overview page and open the app.

image

Your Streamlit app is deployed!