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.

1 Like

Hi @Baris_Can_Tayiz

Thanks for the details.

I followed same steps as you mentioned above but I’m getting below error.

2021-04-11T02:32:15.929862+00:00 heroku[web.1]: Starting process with command sh setup.sh && streamlit run app.py
2021-04-11T02:32:18.558538+00:00 heroku[web.1]: Process exited with status 2
2021-04-11T02:32:18.622439+00:00 heroku[web.1]: State changed from starting to crashed
2021-04-11T02:32:18.518709+00:00 app[web.1]: setup.sh: 2:
2021-04-11T02:32:18.518744+00:00 app[web.1]: setup.sh: 3: cannot create /app/.streamlit/config.toml

Kindly help on this issue.

Thanks

It may help to unroll setup.sh as follows:

mkdir -p ~/.streamlit/
echo "[general]"  > ~/.streamlit/credentials.toml
echo "email = \"my@email.com\""  >> ~/.streamlit/credentials.toml
echo "[server]"  > ~/.streamlit/config.toml 
echo "headless = true"  >> ~/.streamlit/config.toml
echo "port = $PORT"  >> ~/.streamlit/config.toml
echo "enableCORS = true"  >> ~/.streamlit/config.toml

I have already added a directory .streamlit/config.toml and put my custom theme configuration there. Kindly check my Github repo. It’s functioning okay in Streamlit Share. Now I want to deploy it on Heroku too. But I am getting confused about how to set up the setup.sh file. Kindly help me with it. Is it possible to directly connect my config.toml file to the Procfile? What should I do to keep both Streamlit Share and Heroku app functioning?

In Heroku you must have a [server] section in config.toml, with headless and port entries as shown. Also remove sh setup.sh && from the Procfile as you don’t have a setup.sh in your repo.

However, I would keep the setup.sh and Procfile. But, change the [server] line to have >> instead of >. This will append the lines to your existing config.toml file.

Kindly elaborate by showing the code. I have tried the following:
.streamlit/config.toml:

[server]
headless = true
port = $PORT
enableCORS = false

[theme]
primaryColor="#FF7903"
backgroundColor="#0E1117"
secondaryBackgroundColor="#31333F"
textColor="#FAFAFA"
font="sans serif"

Procfile:

web: streamlit run app.py

Both my Streamlit Share and Heroku app are not working. I think there’s an issue in adding [server] line in config.toml!

Continuing the discussion from Not able to deploy to Heroku | Error in creating config.toml:

I have done the following and it’s working now:

  • .streamlit/config.toml:
[theme]
primaryColor="#FF7903"
backgroundColor="#0E1117"
secondaryBackgroundColor="#31333F"
textColor="#FAFAFA"
font="sans serif"
  • setup.sh:
mkdir -p ~/.streamlit/
echo "[general]  
email = \"me@gmail.com\""  > ~/.streamlit/credentials.toml
echo "[server]
headless = true
port = $PORT
enableCORS = true"  >> ~/.streamlit/config.toml
  • Procfile:
web: sh setup.sh && streamlit run app.py

But another thing I want to know, what does enableCORS = true mean? I checked some use false there. Should I put true or false here? Also, What should I do if I like to show the credential info (my name, email) at the bottom beside Made with Streamlit in my Heroku app?

1 Like

@rafisics You may not require CORS for your app, and it works hand in hand with your client app calling server in different domains and the request/response headers they send each other. Setting this switch does not magically enable CORS; it just tells Heroku’s proxies how to handle requests and responses. It’ll likely come into play when you use Streamlit’s iframe and custom components when making “cross-domain (origin)” requests. See: Cross-Origin Resource Sharing (CORS) - HTTP | MDN

1 Like

So, it’s safe to remove te line, right?
Heroku vs Streamlit Share - which is better now for deploying the web app on the basis of overall performance while staying in the free plan?

Just make it “false”.

Heroku vs. Streamlit Sharing depends on what perf you need. Currently you can pay to increase perf on Heroku, but I expect Streamlit Sharing will be better when it goes into GA and you can pay for perf/resource upgrades. It’ll be highly tuned for Streamlit apps and have enterprise team features that other platforms won’t have.

1 Like

I am interested to stay as a free user of both platforms now. My main target is to embed my app on my website/blog post. I don’t know for sure. But as I have deployed the same app (GitHub - rafisics/suvat_calculator: 'Newtonian equations of linear motion' calculator a.k.a. SUVAT calculator) on both platforms, it seems like my Heroku app is comparatively a bit slower. But I prefer using a short URL for my app which Heroku provides. Is there anything can you suggest to increase my Heroku app perf except paying? :slight_smile: Also, is there any chance of getting a custom/short URL for my Streamlit Share app?

You get what you pay for, is the old adage! :slight_smile:

I’m not experienced in running Streamlit apps on Google Colab, but believe it’s possible, and the claim is there aren’t any perf. limits. Search on the web for “deploying streamlit on google colab” and look at @Jesse_JCharis’s article here.

@randyzwitch has just posted this Deployment Guide Wiki with quite a few alternatives.

1 Like

Wow! That’s interesting. Thanks for sharing!

1 Like

@asehmi Thank you, I am able to deploy on Heroku now.

1 Like

I have a similar problem, but what worked for the original poster is still throwing an error for me. I already set-up a config.toml file, so I don’t want to overwrite it (i.e. I used >> instead of >). My files look like this:

./streamlit/config.toml

[theme]
primaryColor="#49a149"
secondaryBackgroundColor="#f1f1f1"
textColor="#4c4c4c"
font="Avenir"

setup.sh

mkdir -p ~/.streamlit/

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

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

For the last section in my setup.sh file, I first tried this, but it also didn’t work:

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

The error I’m getting is:

2021-08-16T20:59:30.575265+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/toml/decoder.py", line 514, in loads
2021-08-16T20:59:30.575617+00:00 app[web.1]:     raise TomlDecodeError(str(err), original, pos)
2021-08-16T20:59:30.575731+00:00 app[web.1]: toml.decoder.TomlDecodeError: Found tokens after a closed string. Invalid TOML. (line 5 column 1 char 86)
2021-08-16T20:59:30.959049+00:00 heroku[web.1]: Process exited with status 1
2021-08-16T20:59:31.163943+00:00 heroku[web.1]: State changed from starting to crashed
2021-08-16T20:59:44.394116+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=earnings-spread.herokuapp.com request_id=a01f626a-c479-4b9a-b928-92f1c828a6fd fwd="66.65.162.168" dyno= connect= service= status=503 bytes= protocol=https
2021-08-16T20:59:44.563821+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=earnings-spread.herokuapp.com request_id=600dcd34-ec93-4c51-ab3b-135870a65faa fwd="66.65.162.168" dyno= connect= service= status=503 bytes= protocol=https

I would really appreciate any help!