无网络内网部署Shiny应用求助:R新手的后续操作疑问
Hey there! I’ve helped many folks deploy Shiny apps to offline servers, so let’s walk through your two key questions clearly.
1. Configuring Access Address for Your Shiny App
First, let’s make sure your Shiny Server is set up correctly and accessible:
Check Shiny Server status
Start by verifying the service is running (and set to start on boot). Run these commands in your server’s terminal:# Check current status sudo systemctl status shiny-server # If it's not running, start it sudo systemctl start shiny-server # Set to auto-start on server reboot sudo systemctl enable shiny-serverDefault Access Path
Shiny Server uses port3838by default. If you placed yourapp.Rdirectly in/srv/shiny-server/(no subfolder), your app will be accessible at:http://<your-server-intranet-IP>:3838/If you put
app.Rinside a subfolder (e.g.,/srv/shiny-server/myapp/app.R), the address becomes:http://<your-server-intranet-IP>:3838/myappCustomize Port or Path (Optional)
If you want to use a different port (like port 80 for standard HTTP) or a custom URL path:- Edit the Shiny Server config file with sudo access:
sudo nano /etc/shiny-server/shiny-server.conf - To change the port, find the line
listen 3838;and replace3838with your desired port (e.g.,listen 80;). - To add a custom path (e.g.,
/myapppointing to your app folder), add this block to the config:location /myapp { site_dir /srv/shiny-server/myapp; log_dir /var/log/shiny-server; directory_index on; } - Save the file (Ctrl+O, Enter, then Ctrl+X in nano) and restart Shiny Server:
sudo systemctl restart shiny-server
- Edit the Shiny Server config file with sudo access:
2. Installing R Packages Offline
Since your server has no internet, you’ll need to pre-download packages on a connected machine and transfer them over:
Step 1: Download Packages (on a machine with internet)
Open R/RStudio on a connected computer and download all required packages (including dependencies!) to a local folder. For example:# List all packages your app uses (e.g., shiny, ggplot2, dplyr) required_pkgs <- c("shiny", "ggplot2", "dplyr") # Download source packages (works across Linux/macOS/Windows) download.packages( pkgs = required_pkgs, destdir = "./offline_r_packages", type = "source", dependencies = TRUE # Critical: downloads all nested dependencies )Pro tip: If you’re unsure of all dependencies, run
devtools::install_deps(path = "path/to/your/app", dependencies = TRUE)on the connected machine first—it’ll list every package your app needs.Step 2: Transfer Packages to the Intranet Server
Use a USB drive, internal file share, or any offline transfer tool to copy theoffline_r_packagesfolder to your server (e.g., to/home/your_username/offline_r_packages).Step 3: Install Packages on the Server
Open R on the server and run this command to install from the local files:# Path to your transferred package folder pkg_folder <- "/home/your_username/offline_r_packages" # Install all packages (source files end with .tar.gz) install.packages( pkgs = list.files(pkg_folder, pattern = "\\.tar\\.gz$", full.names = TRUE), repos = NULL, type = "source", dependencies = TRUE )Verify installation by loading a package:
library(shiny)—if no error pops up, you’re good to go!
内容的提问来源于stack exchange,提问作者mehakVT




