
Streamlit is an app framework to deploy machine learning apps built using Python. It is an open-source framework which is similar to the Shiny package in R. Heroku is a platform-as-a-service (PaaS) that enables deployment and managing applications built in several programming languages in the cloud.
According to Central Limit Theorem, as the sample size increases, closer would be the mean of the sample means to the population mean. The distribution of the sample means (a.k.a. sampling distribution of sample means) also looks more Gaussian, irrespective of the underlying population distribution, as the sample size increases, given a sufficient number of samples are drawn from the population. The standard deviation of the sample means (a.k.a. standard error) will be equal to (population standard deviation / square root of sample size).
About the app
This Streamlit app simulates the Central Limit Theorem as the characteristics of the sample and population change. This app enables a user to play with the population range, population size, sample size and number of samples to be drawn. Varying these characteristics of the population and sample has an effect on the population parameters, sample statistics, population distribution and the distribution of sample means. This app visualizes these changes in the distribution of sample means and population.
Folder Structure
Below is the deployment folder structure used to deploy the app to Heroku.

central_limit_theorem.py
This Python script (.py file, not a notebook) contains the code of the Streamlit app.
requirements.txt
‘requirements.txt’ file specifies the packages to be installed. The versions of the packages must be specified to avoid the ‘it works on my machine’ problem. The version of the packages must match with the ones in our Conda environment. The ‘requirements.txt’ file we’ll be using is shown below.
matplotlib==3.4.1
numpy==1.20.2
pandas==1.2.3
streamlit==0.79.0
setup.sh
‘setup.sh’ specifies the commands to be executed to configure the environment before running the app. In our ‘setup.sh’, we first create a ‘.streamlit’ directory to store the credentials and config files. Then, we specify the e-mail registered with streamlit.io and write it to a ‘credentials.toml’ file. Then, we add the config details to the ‘config.toml’ file. Both these files reside in the ‘.streamlit’ directory.
mkdir -p ~/.streamlit/
echo "
[general]n
email = "email@domain"n
" > ~/.streamlit/credentials.toml
echo "
[server]n
headless = truen
enableCORS=falsen
port = $PORTn
" > ~/.streamlit/config.toml
Procfile
‘Procfile’ lists the commands to be executed to start the app. In our ‘Procfile’, we’ll first run ‘setup.sh’ that creates the required config files and then run the app using the ‘streamlit run’ command.
web: sh setup.sh && streamlit run iris_streamlit_demo.py
Deploying the app to Heroku
- Log in to your Heroku account and select ‘create new app’ from the ‘New’ menu on the top-right.

- Enter the name of your app (any name based on the availability) and click ‘Create app’.

- Select the deployment method. Since, I’ve used GitHub to host the code files (remote repo), I’ll choose that option. You may need to verify your GitHub credentials to connect, if you are doing it for the first time.

- Enter the name of the GitHub repo which you want to deploy and click ‘Search’ and click ‘Connect’

- Then select the branch to deploy and click ‘Deploy Branch’. I’m not planning to modify the app in future, so I haven’t enabled automatic deployment.

- Once your application is successfully deployed you’ll see the message and click ‘View’ to view the app.


The app deployed to Heroku can be found [here](https://share.streamlit.io/ksv-muralidhar/central_limit_theorem/main/central_limit_theorem.py). Since, the app is built only for demonstration purpose, I’m using free dynos, which may result in poor app performance. At times, it may take longer for the app to start, as the dyno may go into sleep mode when inactive for a longer period. Also, this app takes in the inputs through sliders (without using a submit button) and works with large Numpy arrays, this may crash the app and make it inaccessible. However, I used the ‘@st.cache’ decorator which is said to improve the app’ performance while performing high resource demanding computations. You can also access the app from Streamlit Sharing here.
Know more about my work at https://ksvmuralidhar.in/