@aminsadeghi
I have spent some time on the issue and eventually found a solution to the problem (inspired from the solution found here 20. You may try to follow the below steps and see if it helps:
(Indeed, I have my Raspberry Pi reinstalled earlier today due to some other technical issues and hence I am sure that the below steps work well in a newly installed Debian 10 OS that is hosted with an Apache2 server )


Create a config.toml under ~/. streamlit folder:

cd ~/. streamlit
sudo nano config.toml



Type the below in the config.toml and save it:

[server]
port = 8501
enableCORS = false



Ensure that the below a2enmods are enabled:

sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel



Navigate/ Create an Apache .conf file and type the below:
(Replace the text with your domain in the <Your Domain/ Sub-domain> below)

<VirtualHost :80>
ServerName <Your Domain/ Sub-domain>
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /(.) ws://localhost:8501/$1 [P]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /(.*) http://localhost:8501/$1 [P]
ProxyPassReverse / http://localhost:8501 3
</VirtualHost>



sudo a2ensite the config file created in the last step and then sudo service apache2 restart should then be able to solve the “Keep Connecting” issue.