简体   繁体   English

通过在云中运行的笔记本从谷歌驱动器访问电子表格文件

[英]Accessing spreadsheet file from google drive through notebook run in the cloud

I am working on a spare-time project together with some friends.我正在和一些朋友一起做一个业余项目。 What I would like to do is to have an spreadsheet saved on Google Drive (or similar services) that me and my friends will update regularly.我想做的是在 Google Drive(或类似服务)上保存一个电子表格,我和我的朋友会定期更新。 The data from the spreadsheet we want to visualize using Python and Jupyter Notebooks.我们想要使用 Python 和 Jupyter Notebooks 可视化的电子表格中的数据。 My friends are not into programming at all, so I want them to be able to access and run the notebooks in the cloud, eg through mybinder.org.我的朋友根本不喜欢编程,所以我希望他们能够访问和运行云中的笔记本,例如通过 mybinder.org。

I did the credentials stuff from Google API, and it works fine when I run locally.我从谷歌 API 做了凭据,当我在本地运行时它工作正常。 The problem, however, is that since my understanding is that I should not upload credentials to GitHub, mybinder.org is not able to get the credentials that it needs to read the spreadsheet from Google Drive.然而,问题在于,由于我的理解是我不应该将凭据上传到 GitHub,因此 mybinder.org 无法获得从 Google Drive 读取电子表格所需的凭据。 So my question is how I can solve this?所以我的问题是我该如何解决这个问题?

One idea is to create a separate Google Account just for putting the spreadsheet there.一个想法是创建一个单独的 Google 帐户,仅用于将电子表格放在那里。 If I do that then maybe uploading the credentials to GitHub is fine?如果我这样做,那么也许将凭据上传到 GitHub 可以吗? The data from the spreadsheet is not sensitive at all.电子表格中的数据根本不敏感。

You could set the file to be shared with those that have the link by selecting Get shareable link under 'Sharing' and then use the method described here to bring the file into an active Jupyter session.您可以通过选择“共享”下的“ Get shareable link ”将文件设置为与具有链接的人共享,然后使用此处描述的方法将文件放入活动的 Jupyter session。 (More on the use of curl to do that is here .) (更多关于使用curl来做到这一点在这里。)
To have it be otained as CSV you can change the end of the URL of the shareable link from edit?usp=sharing to export?exportFormat=csv , based on here .要将其作为 CSV 获取,您可以根据此处将可共享链接的 URL 的末尾从edit?usp=sharing更改为export?exportFormat=csv
To execute curl in a Jupyter notebooks cell, you'd want to preface the command with an exclamation point so that the task is run in a shell.要在 Jupyter 笔记本单元格中执行curl ,您需要在命令前加上感叹号,以便任务在 shell 中运行。
Then direct the stdout to a file.然后将标准输出定向到文件。
So combining that, the general form of the code cell would be:因此,将其结合起来,代码单元的一般形式将是:

!curl https://docs.google.com/spreadsheets/d/<specific_GUID_key>/export?exportFormat=csv > output.csv

Instead of running the code to retrieve it from a notebook cell, the command without the exclamation point could be placed in a start file so the current data is retrieved each time the session is spun up.无需运行代码从笔记本单元格中检索它,而是可以将不带感叹号的命令放在start文件中,以便每次启动 session 时检索当前数据。 See here for more about the start configuration file for use with Binderhubs/MyBinder.org.有关与 Binderhubs/MyBinder.org 一起使用的start配置文件的更多信息,请参见此处

You may also be interested in using Voila to have them see the visualizations via a dashboard backed by the Jupyter notebook.您可能还对使用Voila让他们通过由 Jupyter 笔记本支持的仪表板查看可视化感兴趣。 It is able to be spawned by sessions backed by MyBinder.org, too.它也可以由 MyBinder.org 支持的会话生成。

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

相关问题 访问 Google Drive 中的电子表格 - Accessing a Spreadsheet in Google Drive 来自 google cloud dataproc python notebook 的 Run.py 文件 - Run .py file from google cloud dataproc python notebook 通过python访问Google电子表格 - Accessing google spreadsheet through python 从 Python 中的谷歌驱动器访问文件 - Accessing a file from google drive within Python 将 csv 文件从协作笔记本导出到谷歌驱动器 - Export csv file from collab notebook to google drive 通过 Azure notebook 从 blob 容器访问 csv 文件 - Accessing csv file from blob container through Azure notebook 将 geoTIFF 文件从 jupyter notebook 导出到谷歌驱动器,但我的谷歌驱动器中没有任何内容 - Export a geoTIFF file from jupyter notebook to google drive but nothing appears in my google drive 在 Cloud Run 实例中从 Cloud Storage 访问和使用 csv 文件 - Accessing and using csv file from Cloud Storage in Cloud Run instance 如何从谷歌电子表格中提取数据到笔记本 - How to extract data from a google spreadsheet to notebook 如何在 Google Colab 笔记本的“.py”文件中运行 Python 脚本? - How to run a Python script in a '.py' file from a Google Colab notebook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM