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

Shiny App显示‘undefined’,刷新后UI才正常的问题求助

Hey Frank, let's dig into that frustrating 'undefined' issue you're hitting with your Shiny App on ShinyProxy after rebuilding your Docker image. I’ve dealt with similar quirky startup bugs before, so here are some targeted checks and fixes to narrow this down:

1. Audit Docker Image Build Changes

First, let’s rule out unintended changes in your new image:

  • Run docker diff <old-image-ID> <new-image-ID> to compare file differences between your working and broken images. Pay close attention to Shiny-related dependencies, config files in /etc/shiny-server/, or R package installations.
  • Double-check your Dockerfile for new steps that might disrupt Shiny’s startup flow. For example, if you added install.packages() without --no-cache-dir, could there be corrupted cached packages? Or did you modify the startup command (like changing shiny-server to a custom script)?
2. Validate ShinyProxy Configuration

Sometimes the issue isn’t the image itself, but how ShinyProxy interacts with it:

  • Open your application.yml and verify the app’s settings:
    • Ensure container-cmd is pointing to the correct entrypoint (usually ["/usr/bin/shiny-server"] or your custom start script).
    • Check if you added any new container-env variables that might interfere with Shiny’s initialization, like an incorrect SHINY_PORT (it should match the port ShinyProxy expects, typically 3838).
    • Increase proxy.timeout from the default 30 seconds to 60 seconds—if your app takes a bit longer to initialize, ShinyProxy might be returning an unready state too early, leading to the 'undefined' message.
3. Debug Shiny App Startup Inside the Container

Let’s check if the app actually runs properly when isolated from ShinyProxy:

  • Start the container normally, then jump into it with docker exec -it <container-ID> bash.
  • Tail the Shiny Server logs in real-time: tail -f /var/log/shiny-server.log—look for warnings or errors that might be happening during startup but not crashing the container (like a missing dependency that fails silently).
  • Manually launch the app inside the container with:
    R -e "shiny::runApp('/path/to/your/app', port=3838, host='0.0.0.0')"
    
    If this throws errors, you’ve found your root cause (likely a broken package or app code issue). If it runs fine, the problem is in ShinyProxy’s connection logic.
4. Check Version Compatibility

Rebuilding images often pulls in updated dependencies—this can break compatibility:

  • Did your new image upgrade Shiny Server or the shiny R package? For example, newer Shiny Server versions (1.5.x+) have changes to WebSocket handling that might clash with older ShinyProxy versions.
  • Try pinning versions in your Dockerfile to match the working image. For example:
    RUN install.packages("shiny", version="1.7.4", repos="https://cran.rstudio.com/")
    
    Or specify a specific Shiny Server base image tag instead of latest: FROM rocker/shiny:4.3.0
5. Test the Minimal Demo App Thoroughly

Since you swapped to a small demo app, use it to isolate variables:

  • First, run the demo image directly without ShinyProxy: docker run -p 3838:3838 <demo-image>—visit localhost:3838 to confirm the app loads instantly. If it doesn’t, the issue is in the demo image itself.
  • If the demo works standalone, check if it uses dynamic UI elements (like renderUI) that might not initialize before ShinyProxy checks for the app state. Add a simple loading spinner or ensure all UI elements are defined upfront in ui.R instead of generating them asynchronously on startup.
Quick Temporary Fix to Test

If you need a quick workaround while debugging, add a startup delay to your ShinyProxy app config to give the app time to fully initialize:

apps:
  - name: my-demo-app
    docker-image: my-demo-image
    container-init-command: "sleep 5"

This tells ShinyProxy to wait 5 seconds before attempting to connect to the app, which can fix timing-related 'undefined' issues.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:20:43