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

在SAP Analytics Cloud中运行Shiny应用遇502错误求助

在SAP Analytics Cloud (SAC)中运行Shiny应用时出现502 Bad Gateway错误

我开发了一个可正常本地运行的Shiny应用,尝试通过SAP Analytics Cloud(SAC)的R功能部署运行。已知Shiny属于SAC官方支持的R包,但在SAC中运行时始终失败,本地使用的脚本和模拟数据与SAC中完全一致,目前遇到的错误为:
502 Bad Gateway: Registered endpoint failed to handle the request

想请教是否有人成功在SAC中运行过Shiny应用,以及如何解决这个问题?


编辑补充:完整测试代码

无需外部输入数据的代码如下:

library(ggplot2)
library(shiny) # 补充添加shiny包加载,原代码遗漏

ui <- fluidPage(
  titlePanel("Bass Diffusion Model Visualisation"),
  
  sidebarLayout(
    sidebarPanel(
      h2("Baseline model (blue)"),
      sliderInput(
        "innovation_base",
        "Innovation effect:",
        min = 0,
        max = 1,
        value = 0.03
      ),
      sliderInput(
        "imitation_base",
        "Imitation effect:",
        min = 0,
        max = 1,
        value = 0.38
      ),
      h2("Challenger model (red)"),
      sliderInput(
        "innovation",
        "Innovation effect:",
        min = 0,
        max = 1,
        value = 0.02
      ),
      sliderInput(
        "imitation",
        "Imitation effect:",
        min = 0,
        max = 1,
        value = 0.42
      )
    ),
    
    mainPanel(
      h2("Rate of adoption"),
      plotOutput("adoptionPlot"),
      h2("Cumulative adoption"),
      plotOutput("cumAdoptionPlot"))
  ))


server <- function(input, output) {
  output$adoptionPlot <- renderPlot({
    bass_base <- 
      difcurve(
        n = 20,
        w = c(input$innovation_base, input$imitation_base, 100),
        type = "bass"
      )
    bass_challenger <- 
      difcurve(
        n = 20,
        w = c(input$innovation, input$imitation, 100),
        type = "bass"
      )
    
    plot_adoption <- ggplot(as.data.frame(bass_base)) +
      aes(y = Adoption, x = 1:nrow(bass_base)) +
      geom_line(colour = "blue") +
      geom_line(data = as.data.frame(bass_challenger), colour = 'red') +
      labs(x = "years")
    
    plot_adoption
  })
  output$cumAdoptionPlot <- renderPlot({
    bass_base <- 
      difcurve(
        n = 20,
        w = c(input$innovation_base, input$imitation_base, 100),
        type = "bass"
      )
    
    bass_challenger <- 
      difcurve(
        n = 20,
        w = c(input$innovation, input$imitation, 100),
        type = "bass"
      )
    
    plot_cumAdoption <- ggplot(as.data.frame(bass_base)) +
      aes(y = `Cumulative Adoption`, x = 1:nrow(bass_base)) +
      geom_line(colour = "blue") +
      geom_line(data = as.data.frame(bass_challenger), colour = 'red') +
      labs(x = "years")
    
    plot_cumAdoption
  })
}

shinyApp(ui = ui, server = server)

解决方案

1. 补全缺失的依赖包

代码中使用了difcurve()函数,但未加载对应的包(该函数通常属于bass或diffusion包)。本地环境可能已安装,但SAC的R环境默认没有部署。需要:

  • 在代码开头添加包加载语句,例如:
    library(bass) # 若difcurve来自bass包
    # 或 library(diffusion) # 若来自diffusion包
    
  • 确认该包在SAC支持的R包列表中,若不在,需通过SAC的包管理流程申请添加。

2. 适配SAC的Shiny运行限制

SAC对Shiny应用有特定约束:

  • 不支持需要长连接的复杂交互组件
  • 应用运行有超时限制,需简化计算逻辑(例如将重复的difcurve调用封装为函数,减少冗余计算)
  • 禁止依赖本地文件或自定义环境变量

3. 测试最小化应用排查问题

先运行最简版Shiny应用验证SAC环境是否正常:

library(shiny)
ui <- fluidPage("Test SAC Shiny")
server <- function(input, output) {}
shinyApp(ui, server)

如果该应用能运行,再逐步添加你的功能模块,定位具体出错的代码段。

4. 排查服务端故障

502错误可能是SAC的R后端服务临时异常,尝试重新部署应用,或联系SAP技术支持确认服务状态。


内容的提问来源于stack exchange,提问作者Guille López

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 01:00:57