You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

无网络内网部署Shiny应用求助:R新手的后续操作疑问

Shiny App Offline Deployment on Intranet Server: Step-by-Step Guide

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-server
    
  • Default Access Path
    Shiny Server uses port 3838 by default. If you placed your app.R directly in /srv/shiny-server/ (no subfolder), your app will be accessible at:
    http://<your-server-intranet-IP>:3838/

    If you put app.R inside a subfolder (e.g., /srv/shiny-server/myapp/app.R), the address becomes:
    http://<your-server-intranet-IP>:3838/myapp

  • Customize Port or Path (Optional)
    If you want to use a different port (like port 80 for standard HTTP) or a custom URL path:

    1. Edit the Shiny Server config file with sudo access:
      sudo nano /etc/shiny-server/shiny-server.conf
      
    2. To change the port, find the line listen 3838; and replace 3838 with your desired port (e.g., listen 80;).
    3. To add a custom path (e.g., /myapp pointing 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;
      }
      
    4. Save the file (Ctrl+O, Enter, then Ctrl+X in nano) and restart Shiny Server:
      sudo systemctl restart shiny-server
      

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 the offline_r_packages folder 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

火山引擎 最新活动