在不依赖本地目录的情况下将 csv 从 zip 读取到闪亮的应用程序中 [英] Read csv from zip into shiny app without relying on local directories

查看:31
本文介绍了在不依赖本地目录的情况下将 csv 从 zip 读取到闪亮的应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个闪亮的应用程序(服务器和用户界面),它在我的计算机上运行良好.今天我试图将它托管在 Shinyapps.io 上,但遇到了一些麻烦.我无法从本地机器中提取数据,它需要在线存放在某处.但是源数据 仅作为 zip 在线提供.我找到了一些关于如何使用 R 将 zip 下载到本地机器的资源,但它们似乎都需要将文件放在本地临时目录中,我认为我无法使用托管的闪亮来做到这一点应用程序.所以我的问题是如何直接在 R/Shiny 中解压然后访问/加载/使用 CSV 文件.

I've written a shiny app (server & ui) and it runs fine on my computer. Today I'm trying to host it on shinyapps.io and having some trouble. I can't pull data from my local machine, it needs to be housed online somewhere. But the source data is only available online as a zip. I've found a few resources on how to use R to download a zip to one's local machine, but they all seem to require putting the file in a local temporary directory, and I don't think I can do that with a hosted shiny app. So my question is how to unzip and then access/load/use CSV files directly within R/Shiny.

相关代码片段如下.这是我需要替换的部分.让我知道发布更多代码是否有帮助 - 我知道这是预期的,但在这种情况下,我不确定它会有所帮助.

Relevant snippet of code is below. This is the section I need to replace. Let me know if it would be helpful to post more code--I know that's expected but in this case I'm not sure it would help.

#load data
library(shiny)
base <- read.csv("/Users/OldJess/Dropbox/R Stuff(Home)/ShinyNames/data/NationalNames.csv", 
                 stringsAsFactors = FALSE, 
                 na.strings = c("NA","","#MULTIVALUE"))

我的闪亮应用在这里:https://jesstme.shinyapps.io/shinynames/

推荐答案

我没有意识到 Shiny 允许我从我的计算机上传原始源数据(作为 CSV)以在我的应用程序中使用,以及 ui&服务器文件.有文件大小限制,但该解决方案对我来说效果很好.

I hadn't realized that Shiny allows me to upload the original source data (as a CSV) from my computer for use in my app, along with the ui & server files. There are file size limits but the solution is working well for me.

这篇关于在不依赖本地目录的情况下将 csv 从 zip 读取到闪亮的应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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