Not able to deploy to Heroku | Error in creating config.toml

I have been working on deploying a simple streamlit app to heroku but I’m facing problems while deploying it.

Have a look at my files:
requirements.txt

streamlit==0.64.0
pandas==1.0.5
numpy==1.19.1
scikit-learn==0.23.1

Procfile
web: streamlit run app.py

setup.sh

mkdir -p ~/.streamlit

echo "[general]
email = tejasmorkar@gmail.com
" > ~/.streamlit/credentials.toml

echo "[server]
headless = true
port = $PORT
enableCORS = false
" > ~/.streamlit/config.toml

When I did heroku logs --tail, it shows the following error:

2020-07-25T03:23:12.600129+00:00 heroku[web.1]: Starting process with command `sh setup.sh && streamlit run app.py`
2020-07-25T03:23:14.650064+00:00 app[web.1]: setup.sh: 2: setup.sh:
2020-07-25T03:23:14.650085+00:00 app[web.1]: setup.sh: 3: setup.sh: cannot create /app/.streamlit/credentials.toml
2020-07-25T03:23:14.650094+00:00 app[web.1]: setup.sh: 6: setup.sh:
2020-07-25T03:23:14.650128+00:00 app[web.1]: setup.sh: 7: setup.sh: cannot create /app/.streamlit/config.toml: Directory nonexistent
2020-07-25T03:23:14.714946+00:00 heroku[web.1]: Process exited with status 2
2020-07-25T03:23:14.754733+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-25T03:23:14.757325+00:00 heroku[web.1]: State changed from crashed to starting
2020-07-25T03:23:30.513564+00:00 heroku[web.1]: Starting process with command `sh setup.sh && streamlit run app.py`
2020-07-25T03:23:31.000000+00:00 app[api]: Build succeeded
2020-07-25T03:23:33.119787+00:00 app[web.1]: setup.sh: 2: setup.sh:
2020-07-25T03:23:33.120315+00:00 app[web.1]: setup.sh: 3: setup.sh: cannot create /app/.streamlit/credentials.toml
2020-07-25T03:23:33.120323+00:00 app[web.1]: setup.sh: 6: setup.sh:
2020-07-25T03:23:33.120324+00:00 app[web.1]: setup.sh: 7: setup.sh: cannot create /app/.streamlit/config.toml: Directory nonexistent
2020-07-25T03:23:33.183786+00:00 heroku[web.1]: Process exited with status 2
2020-07-25T03:23:33.229579+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-25T03:23:51.780744+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fast-castle-31983.herokuapp.com request_id=a3d025e2-7643-442d-958f-d2604306363f fwd="157.33.131.110" dyno= connect= service= status=503 bytes= protocol=https

Setup.sh

mkdir -p ~/.streamlit

echo "[server]
headless = true
port = $PORT
enableCORS = false
" > ~/.streamlit/config.toml

Procfile


web: sh setup.sh && streamlit run app.py

requirements.txt


streamlit==0.71.0

numpy==1.19.3

pandas==1.1.4

app.py


import streamlit as st

import numpy as np

import pandas as pd

st.title("Hello World")

You can declare a runtime.txt for python version also.

The codes
-git init
-heroku login
-heroku create
-git add .
-git commit -m “hello world”
-git push heroku master
-heroku ps:scale web=1
-heroku open

You can create your Procfile and setup.sh on visual studio code.
pip install pipreqs and -pipreqs command will create requirements.txt

If you select interpreter path the Streamlit will detect python version.

That is worked for a simple “hello world” app. I suggest you should solve your deployment issues with simple hello world types to see errors and needs etc.

Good day.