简体   繁体   English

在 Dockerfile 中使用 Shiny::runApp 和超时问题

[英]Using shiny::runApp in Dockerfile and issues with timeout

I have a Shiny app in a Docker container deployed to AWS.我在部署到 AWS 的 Docker 容器中有一个 Shiny 应用程序。

I unfortunately cannot provide a fully reproducible example given that there are many moving pieces here with the app.R file, the app connecting to our SQL database, information to connect to AWS, etc.不幸的是,我无法提供一个完全可重现的示例,因为这里有许多带有app.R文件的移动部分、连接到我们 SQL 数据库的应用程序、连接到 AWS 的信息等。

However, the Dockerfile installs all the necessary dependencies and ends with running the Shiny app via Rscript that just does shiny::runApp('.', host='0.0.0.0', port=8080) .但是,Dockerfile 安装了所有必要的依赖项,并以通过Rscript运行 Shiny 应用程序结束,该应用程序只执行 Shiny shiny::runApp('.', host='0.0.0.0', port=8080)

This deploys just fine, and I can access it via the web address in which it was assigned.这部署得很好,我可以通过分配它的网址访问它。

However, if a user ever switches to a new window, changes tabs for too long, or leaves it idle for too long, the app times out and does the familiar "graying-out" that Shiny apps do.但是,如果用户切换到新窗口、更改选项卡太长时间或使其闲置太长时间,应用程序将超时并执行 Shiny 应用程序所做的熟悉的“变灰”。

Is there a way to prevent this from happening when I do shiny::runApp() ?当我执行shiny::runApp()时,有没有办法防止这种情况发生? I do not find any timeout arguments in the documentation.我在文档中找不到任何超时参数。

Context : Shiny uses a websocket (RFC 6455) for its constant client-server communication.上下文:Shiny 使用websocket (RFC 6455)进行持续的客户端-服务器通信。 If, for whatever reason, this websocket connection gets dicsonnected, the user experience is the described "greying out".如果出于某种原因,此 websocket 连接断开连接,则用户体验将被描述为“灰显”。 Depending on your setup, there are multiple possibilities why this happens, where one option is the most likely: There is a proxy or load balancer that has an unexpected http time out value set.根据您的设置,发生这种情况的可能性有多种,其中一个选项最有可能:代理或负载均衡器设置了意外的 http 超时值。

Answer : From our own setup, standalone Shiny app (no shiny-server involved) using Kubernetes and nginx-ingress, the default settings allowed for lingering connections for up to 60 seconds.:根据我们自己的设置,使用 Kubernetes 和 nginx-ingress 的独立 Shiny 应用程序(不涉及 Shiny 服务器),默认设置允许延迟连接长达 60 秒。 We were able to manipulate this behaviour by adding the following annotations to our manifest:我们能够通过在清单中添加以下注释来操纵这种行为:

kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-read-timeout: '3600'
    nginx.ingress.kubernetes.io/proxy-send-timeout: '3600'

Mind you, depending on your configuration there could be more proxies involved which might complicate things (don't ask me how I know...).请注意,根据您的配置,可能会涉及更多代理,这可能会使事情复杂化(不要问我是怎么知道的......)。

Alternatively you can try to prevent any timeout by adding a heartbeat mechanism to the Shiny application.或者,您可以尝试通过向 Shiny 应用程序添加心跳机制来防止任何超时。 Some ways of doing this are discussed in this issue on GitHub .在 GitHub 上的这个 issue中讨论了一些这样做的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM