R:在已部署的ShinyApp中仅向.RData加载一次 [英] R : Load only once a .RData in a deployed ShinyApp

查看:52
本文介绍了R:在已部署的ShinyApp中仅向.RData加载一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Shiny Server 部署ShinyApp.要运行,我的应用程序需要来自 .RData 文件(〜300 Mo)的数据.该 .RData 文件使用位于 global.R 文件中的 load(...)语句加载.由于计算机的功能,加载可能需要几分钟,这对用户来说是不友好的.

I need to deploy a ShinyApp with Shiny Server. To run, my app need data from a .RData file (~300 Mo). This .RData file is loaded with a load(...) statement located in a global.R file. Function of the computer, the loading may need several minutes what is unfriendly for the user.

如何才能让 .RData 文件只加载一次,这样每个新用户都不需要重新加载 .RData 文件?

How can we do in order to make the .RDate file load only once so that each new user does not need to re-load the .RData file ?

谢谢.

推荐答案

如果将对象加载到 global.R 中,则仅应加载一次.第一个用户之后的每个用户都应该可以快速访问您的应用程序.

If you load the object in global.R, then just once it should be loaded. Every user after the first should have a fast access to your application.

如果您是在本地开发应用程序,则可以通过以下方式测试我的意思.例如,使用

If you are developing locally your app, you can test what I'm saying in the following way. Start your application with, for instance,

 runApp(port=5050)

仅用于设置端口.您的浏览器需要一些时间才能显示该应用程序.加载后,记下您应用程序的地址(应为 127.0.0.1:5050 ),关闭该应用程序的浏览器标签(但不要停止R!),打开一个新标签页,然后将上面的地址放在地址栏中.现在,访问您的应用程序应该很快.

just to set the port. You need some time for your browser to display the app. After loading, take note of the address of your app (should be 127.0.0.1:5050), close the browser tab of the app (but don't stop R!), open a new tab and put the above address in the address bar. Now, access to your app should be very fast.

这只是说,只要启动并运行Shiny,就会在开始时执行 global.R 中的命令,并将它们的评估结果放入R全局环境中.用户连接到应用程序时,它们不会执行.

This just to say that as long as shiny is up and running, the commands in global.R are executed at the beginning and their evaluation is put in the R global environment. They are not executed any time a user connects to the app.

还考虑到,如果使用 compress = FALSE 自变量保存 Rdata ,则可以加快加载速度.这样,您的文件会更大,但加载起来会更快.

Consider also that you can speed up the loading of an Rdata if you save it with the compress=FALSE argument. In this way, your file will be bigger, but loading it will be faster.

这篇关于R:在已部署的ShinyApp中仅向.RData加载一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆