How to Install Shiny Server on AlmaLinux 9 or Rocky Linux 9
Install R and Shiny Server on AlmaLinux 9 or Rocky Linux 9, open the firewall, deploy your first Shiny app and learn where the config and logs live.
Shiny Server is Posit's open-source web server for hosting R Shiny applications: you drop an app into a directory and it is served at its own URL. This guide installs R, the shiny package and Shiny Server on AlmaLinux 9 or Rocky Linux 9, opens the firewall, and deploys a first app. CentOS 7 reached end of life on 30 June 2024; Shiny Server's administrator guide now lists Red Hat Enterprise Linux 8 and later as supported, which covers the RHEL 9 rebuilds used here.
Requirements
- An AlmaLinux 9 or Rocky Linux 9 server on x86-64. Shiny Server is published for that architecture only.
- At least 2 GB of RAM. The
shinypackage and its dependencies are compiled from source during installation, which is slow and memory-hungry on smaller machines. - A user with
sudorights.
Step 1: Enable EPEL and install R
R is not in the base repositories. It comes from EPEL, and some of its dependencies come from the CRB repository, so enable both:
sudo dnf install dnf-plugins-core
sudo dnf config-manager --set-enabled crb
sudo dnf install epel-releaseUpdate the system and install R:
sudo dnf update
sudo dnf install RConfirm that R is on the path:
R --versionStep 2: Install the shiny R package
Shiny Server needs the shiny package to be available to the user that runs the apps. Installing it as root puts it in the system library, where every user can load it:
sudo su - -c 'R -e "install.packages(\"shiny\", repos = \"https://cran.r-project.org\")"'Compilation takes several minutes. The welcome page that ships with Shiny Server also includes an R Markdown example; if you want that to render, or plan to host R Markdown documents, install rmarkdown the same way:
sudo su - -c 'R -e "install.packages(\"rmarkdown\", repos = \"https://cran.r-project.org\")"'Install any other packages your apps need with the same command.
Step 3: Download and install Shiny Server
Posit publishes one RPM for the whole RHEL family in a directory named centos8; the same package is used on RHEL 9 rebuilds. A VERSION file in that directory holds the current release number, so you can fetch the newest build without editing the URL by hand:
cd ~
VERSION=$(curl -s https://download3.rstudio.org/centos8/x86_64/VERSION)
echo "$VERSION"
curl -O "https://download3.rstudio.org/centos8/x86_64/shiny-server-${VERSION}-x86_64.rpm"Install the package. It is not signed with a key that dnf knows, so the official instructions pass --nogpgcheck:
sudo dnf install --nogpgcheck "./shiny-server-${VERSION}-x86_64.rpm"The package installs the software to /opt/shiny-server, creates a system user named shiny, and registers a systemd service. Make sure it is running and starts at boot:
sudo systemctl enable --now shiny-server
sudo systemctl status shiny-serverStep 4: Open the firewall
Shiny Server listens on TCP port 3838 by default:
sudo firewall-cmd --permanent --add-port=3838/tcp
sudo firewall-cmd --reloadOpen http://203.0.113.10:3838/ in a browser, replacing the address with your server's IP. You should see the Shiny Server welcome page with a live sample app on the right.
Step 5: Deploy your own app
Apps live in /srv/shiny-server. Each sub-directory that contains an app.R (or a ui.R and server.R pair) is served under its directory name. Create one:
sudo mkdir /srv/shiny-server/hello
sudo nano /srv/shiny-server/hello/app.RPaste a minimal app:
library(shiny)
ui <- fluidPage(
titlePanel("Hello from Shiny Server"),
sliderInput("n", "Number of points", min = 10, max = 500, value = 100),
plotOutput("plot")
)
server <- function(input, output) {
output$plot <- renderPlot({
plot(rnorm(input$n), rnorm(input$n))
})
}
shinyApp(ui, server)The app is available immediately at http://203.0.113.10:3838/hello/; no restart is needed for new or changed apps.
Configuration and logs
The configuration file is /etc/shiny-server/shiny-server.conf. The default is short:
run_as shiny;
server {
listen 3838;
location / {
site_dir /srv/shiny-server;
log_dir /var/log/shiny-server;
directory_index on;
}
}Change listen to use another port, and set directory_index off; to stop visitors from browsing the list of apps. After editing, restart the service. A restart stops all running apps and disconnects their users:
sudo systemctl restart shiny-serverTo load the new configuration without interrupting open sessions, send the main process a hang-up signal instead:
sudo systemctl kill -s HUP --kill-who=main shiny-serverEach app writes its own log file to /var/log/shiny-server/; that is the first place to look when an app fails to start. Messages from the server itself go to /var/log/shiny-server.log:
sudo tail -n 50 /var/log/shiny-server.logTo upgrade, download the newer RPM as in Step 3 and install it over the existing one. Your configuration and the contents of /srv/shiny-server stay in place.
Frequently asked questions
Does Shiny Server support HTTPS and logins?
The open-source edition serves plain HTTP and has no authentication. Put a reverse proxy such as Nginx in front of it to add TLS and, if needed, basic authentication. The proxy must pass WebSocket upgrade headers, because Shiny apps talk to the browser over a WebSocket. Once the proxy is in place, close port 3838 in the firewall again.
An app fails with "there is no package called …". Why?
Apps run as the shiny user, which only sees packages in the system library or in its own library. A package you installed in your personal library under your own account is invisible to it. Install the package as root, as in Step 2.
I upgraded an R package but the app still uses the old one. How do I restart a single app?
Edits to an app's own code are picked up for new sessions automatically, but package upgrades are not. Create or update a file named restart.txt in the app directory, for example sudo touch /srv/shiny-server/hello/restart.txt. Shiny Server starts a fresh R process for the next visitor. The administrator's guide describes this and the other per-app settings.