This tutorial will show some neccessay steps to host and deploy a python shiny app on a local linux server.
-
Create a conda virtual environment
conda create -n shiny python=3.12
-
Install Python Shiny
pip install shiny
- For this example, we will use
app.py
inshiny_app
directory.
- Refer to the official documentation for an open source option to set up shiny Server.
-
Follow instructions started from Step 3 of this official link to install Shiny Server.
-
Command lines to download and install Shiny Server for Ubuntu
sudo apt-get install gdebi-core
wget https://download3.rstudio.org/ubuntu-18.04/x86_64/shiny-server-1.5.22.1017-amd64.deb
sudo gdebi shiny-server-1.5.22.1017-amd64.deb
-
Clear out the contents of
/srv/shiny-server
and replace it withshiny_app
. For example,/srv/shiny-server/shiny_app/app.y
will be serverd fromhttp://callisto:3838/shiny_app
(assumingcallisto
is the hostname of your ubuntu server).
-
Point shiny server to an absolute path to a virtual environment, e.g.,
/home/usr/anaconda3/envs/shiny
. Edit the file/etc/shiny-server/shiny-server.conf
(root privileges are required). Add a line withpython /home/usr/anaconda3/envs/shiny
. Change the user afterrun_as
to your user name (this step might be not needed). The modifiedshiny-server.conf
may look like this:# Use system python3 to run Shiny apps python /home/usr/anaconda3/envs/shiny; # Instruct Shiny Server to run applications as the user "ichxw" run_as ichxw; # Define a server that listens on port 3838 server { listen 3838; # Define a location at the base URL location / { # Host the directory of Shiny Apps stored in this directory site_dir /srv/shiny-server/; # Log all Shiny output to files in this directory log_dir /var/log/shiny-server; # When a user visits the base URL rather than a particular application, # an index of the applications available in this directory will be shown. directory_index on; } }
-
Restart the ubuntu server to apply the changes in
/etc/shiny-server/shiny-server.conf
:sudo reboot
-
Find log files in
/var/log/shiny-server.log
and/var/log/shiny-server/*.log
.
- Refer to this link for advanced guidelines.
-
As stated in the guideline: The installer will automatically deploy the necessary scripts to ensure that Shiny Server is started automatically on boot. When possible, we use
systemd
orUpstart
to manage the shiny-server service. -
Start/restart or stop the server mannually
sudo systemctl start shiny-server
sudo systemctl stop shiny-server
sudo systemctl restart shiny-server
-
Check the status of the shiny-server service
sudo systemctl status shiny-server
-
Enable or disablethe Shiny Server to run automatically at boot time:
sudo systemctl enable shiny-server
sudo systemctl disable shiny-server