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:
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 changingshiny-serverto a custom script)?
Sometimes the issue isn’t the image itself, but how ShinyProxy interacts with it:
- Open your
application.ymland verify the app’s settings:- Ensure
container-cmdis pointing to the correct entrypoint (usually["/usr/bin/shiny-server"]or your custom start script). - Check if you added any new
container-envvariables that might interfere with Shiny’s initialization, like an incorrectSHINY_PORT(it should match the port ShinyProxy expects, typically 3838). - Increase
proxy.timeoutfrom 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.
- Ensure
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:
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.R -e "shiny::runApp('/path/to/your/app', port=3838, host='0.0.0.0')"
Rebuilding images often pulls in updated dependencies—this can break compatibility:
- Did your new image upgrade Shiny Server or the
shinyR 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:
Or specify a specific Shiny Server base image tag instead ofRUN install.packages("shiny", version="1.7.4", repos="https://cran.rstudio.com/")latest:FROM rocker/shiny:4.3.0
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>—visitlocalhost:3838to 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 inui.Rinstead of generating them asynchronously on startup.
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

