You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Shiny的Flexdashboard实时部署咨询(Linux/低成本服务器)

Got it, let's walk through exactly how to get your Shiny flexdashboard app deployed on a Linux (or low-cost) server with real-time Excel data sync. I’ve tackled this scenario a few times, so here’s a practical, step-by-step guide:

1. Pick a Low-Cost Server Option

You don’t need a fancy server—these budget-friendly options work perfectly:

  • AWS EC2 t2.micro (free tier eligible for 12 months)
  • DigitalOcean Droplet ($5/month, 1GB RAM/1 CPU)
  • Linode Nanode ($5/month, similar specs to DO)
  • Even a local Linux machine with a public IP (if you have one)
2. Set Up the Server Environment

Start by getting your Linux server (Debian/Ubuntu recommended) ready:

  • Update system packages:
    sudo apt update && sudo apt upgrade -y
    
  • Install R and dev tools:
    sudo apt install r-base r-base-dev -y
    
  • Install Shiny Server:
    # Install gdebi first to handle dependencies
    sudo apt install gdebi-core -y
    # Download the latest Shiny Server package (check RStudio's site for updates)
    wget https://download3.rstudio.org/ubuntu-18.04/x86_64/shiny-server-1.5.20.1002-amd64.deb
    # Install the package
    sudo gdebi shiny-server-1.5.20.1002-amd64.deb
    
  • Install required R packages: Open an R session and run:
    install.packages(c("flexdashboard", "shiny", "readxl", "reactivePoll"))
    
3. Prepare Your App for Real-Time Updates

The key to syncing Excel changes is using reactivePoll to check for file modifications and reload data automatically. Here’s how to adjust your RMarkdown file:

---
title: "Real-Time Status Dashboard"
output: flexdashboard::flex_dashboard
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(readxl)

# Function to check when the Excel file was last modified
check_file_timestamp <- function() {
  file.info("data.xlsx")$mtime
}

# Function to read the Excel data
load_excel_data <- function() {
  read_excel("data.xlsx")
}

# Create a reactive data object that updates on file changes
live_data <- reactivePoll(
  intervalMillis = 5000,  # Check every 5 seconds (adjust as needed)
  session = NULL,
  checkFunc = check_file_timestamp,
  valueFunc = load_excel_data
)

Key Metrics

renderValueBox({
  data <- live_data()
  valueBox(
    value = nrow(data),
    caption = "Total Entries",
    icon = "fa-table"
  )
})

Trend Chart

renderPlot({
  data <- live_data()
  # Replace with your own visualization code
  plot(data$date, data$value, type = "l", col = "blue", lwd = 2)
})
# 4. Deploy the App to the Server
- Create an app folder in Shiny Server’s default directory:
  ```bash
  sudo mkdir /srv/shiny-server/my_dashboard
  • Copy your modified .Rmd file and Excel data file to this folder (use scp from your local machine):
    scp dashboard.Rmd data.xlsx your_username@server_ip:/srv/shiny-server/my_dashboard/
    
  • Fix file permissions so Shiny Server can access the data:
    sudo chown shiny:shiny /srv/shiny-server/my_dashboard/data.xlsx
    
5. Configure Shiny Server (Optional but Useful)

Edit the Shiny Server config file to customize access:

sudo nano /etc/shiny-server/shiny-server.conf

Add a block for your app (adjust paths as needed):

server {
  listen 3838;  # Default Shiny port
  location /my_dashboard {
    site_dir /srv/shiny-server/my_dashboard;
    log_dir /var/log/shiny-server;
    directory_index on;
  }
}

Restart Shiny Server to apply changes:

sudo systemctl restart shiny-server

Open the server’s firewall for port 3838:

sudo ufw allow 3838

(For cloud servers, also add an inbound rule for port 3838 in your provider’s security group.)

6. Sync Excel Changes to the Server

Choose a method to get your local Excel updates to the server:

  • Manual sync: Use scp every time you update the file (simple but tedious).
  • Auto-sync with cloud storage: Use rclone to sync Dropbox/Google Drive to the server. Install rclone, connect your cloud account, then set up a recurring sync:
    rclone sync your_remote:path/to/data.xlsx /srv/shiny-server/my_dashboard/data.xlsx --daemon --interval 30s
    
  • User uploads: Add a file input to your dashboard so users can upload Excel files directly (overwrites the server’s data file):
    ## Upload Updated Data
    ```{r}
    fileInput("excel_upload", "Upload New Excel File", accept = ".xlsx")
    
    observeEvent(input$excel_upload, {
      req(input$excel_upload)
      file.copy(input$excel_upload$datapath, "data.xlsx", overwrite = TRUE)
    })
    
7. Test the Real-Time Functionality
  • Visit your dashboard in a browser: http://your_server_ip:3838/my_dashboard
  • Modify your Excel file, sync it to the server, and wait 5 seconds (or your chosen interval)—the dashboard should refresh automatically with the new data.
Critical Tips to Avoid Headaches
  • Don’t set the intervalMillis too low (e.g., <1 second)—it’ll eat up server resources on low-cost plans.
  • Check Shiny Server logs if something breaks: /var/log/shiny-server/
  • For secure access, set up Nginx as a reverse proxy and add HTTPS with Let’s Encrypt (free certificates).

内容的提问来源于stack exchange,提问作者Praneeth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:26:03