How to really share a Jupyter notebook uploaded to Google Colab? - python

I uploaded a Jupyter .ipynb notebook to Google CoLab using File->Upload Notebook.
Renamed it, made some edits, and saved it. Great.
However, when I do "Share"->"Anyone with a link can view", then copy the link and open it in another (or private) browser window, I
(1) am required to log in to a Google account, and
(2) get this pop-up: "Notebook loading error. There was an error loading this notebook. Ensure that the file is accessible and try again."
and buried in the displayed error is: "403 This file cannot be downloaded by the authenticated user."
This confuses me about the behaviour of Colab notebooks vs. other Drive files. Ordinarily, the "anyone with a link can view" on a Drive file does not require the viewing user to be logged in to a Google account. That's confusion #1. Confusion #2: why is Colab trying to "download" anything at all, as indicated in the 403? I assumed the file would be viewable within Colaboratory within the user's browser, just as it is for the notebook owner.
I would like to invite (non-coding) colleagues to view my Colab notebook, with or without a Google account, and without any particular coding or Google savvy. Any ideas on how to do this?

Possibly this is useful until a better solution is available...
This happens to me when "Disable options to download, print, and copy for commenters and viewers" is selected in advanced options...
I was able to share the notebook by deselecting this option...

Related

How to download a file from google drive without showing this action in the change history

If I have access to a folder with some files in google drive, it's possible to download this folder without showing any changes in history? The owner of the folder should not see that the file was downloaded. If it's possible in python please tell me how to do it.
I used to think about some script (with using Google API) or some service/site to resolve this problem.

can we customize files. Upload() in google colab?

I have tried several ways ,but not able to resolve the problem .can we customize browsing functionality in colab?
I am using uploaded = files.upload() for browse button functionality in colab, but I want whenever user click browse direct dialogue box for given path should open rather than choose files option.
The situation that you discuss is possible if you build your own customized application. But google collab is a proprietary application of google and it has a certain set of operations to do tasks smoothly. Apart from that as you say
"user click browse direct dialogue box for given path should open rather than choose files option"
how it is possible that google colab now what you want to upload. That's why google colab gives you the facility to upload the file as per your requirement. It makes the application more robust and easy to use.
As per Google colab documentation, it is not possible.

'Make this Notebook Trusted to load map: File -> Trust Notebook' error on GitHub

I imported my Jupyter notebook containing folium maps to my Github repository (https://github.com/Nuri-Tas/Data-Analysis/blob/main/Maps/folium%20and%20Geo%20(1).ipynb) but none of the leaflet maps are shown on GitHub. There is only the error 'Make this Notebook Trusted to load map: File -> Trust Notebook' written in the places of maps. I have made my Jupyter file to trust notebook, but I still get this error.
You can use the solution, nbviewer, provided by the Jupyter community for viewing notebooks in 'static' form and for sharing with non-programmers. GitHub is just displaying a preview for developers. There's several issues, one of which you have just found. The 'preview' nature of the GitHub rendering used to enjoy wider appreciaiton because GitHub wouldn't even attempt to render a preview any notebook of substantial length. Since they have tried to allow longer notebooks to render, the inexperienced have not realized this is only meant as a 'quick preview'.
Example using your link you can see nbviewer showing your maps HERE (this is link itself):
https://nbviewer.org/github/Nuri-Tas/Data-Analysis/blob/main/Maps/folium%20and%20Geo%20%281%29.ipynb
You'll note by looking at it you can see the patter of the URL and the relationship to your GitHub URL.
You can easily get this by going to nbviewer and pasting in your GitHub URL https://github.com/Nuri-Tas/Data-Analysis/blob/main/Maps/folium%20and%20Geo%20(1).ipynb and clicking 'Go'.
You can read more about this and explore some other options here.

How can I copy a file from colab to github repo directly? (It is possible to save the notebook in the Github repo)

How can I save a file generated by colab notebook directly to github repo?
It can be assumed that the notebook was opened from the github repo and can be (the same notebook) saved to the same github repo.
Google Colaboratory's integrating with github tends to be lacking, however you can run bash commands from inside the notebook. These allow you to access and modify any data generated.
You'll need to generate a token on github to allow access to the repository you want to save data to. See here for how to create a personal access token.
Once you have that token, you run git commands from inside the notebook to clone the repository, add whatever files you need to, and then upload them. This post here provides an overview of how to do it in depth.
That being said, this approach is kind of cumbersome, and it might be preferable to configure colab to work over an SSH connection. Once you do that, you can mount a folder on the colab instance to a folder on your local machine using sshfs. This will allow you to access the colab as though it were any other folder on your machine, including opening it in your IDE, viewing files in a file browser, and cloning or updating git repositories. This goes more in depth on that.
These are the best options I was able to identify, and I hope one of them can be made to work for you.

Fetching Google Sheet data from locally mounted drive via gspread

I am working on a Google Colab notebook that requires the user to mount google drive using the colab.drive python library. They then input relative paths on the local directory tree (/content/drive/... by default on that mount) to files of interest for analysis. Now, I want to use a Google Sheet they can create as a configuration file. There is lots of info on how to authenticate gspread and fetch a sheet from its HTTPS url, but I can't find any info on how to access the .gsheet file using gspread that is already mounted on the local filesystem of the colab runtime.
There are many tutorials using this flow: https://colab.research.google.com/notebooks/io.ipynb#scrollTo=yjrZQUrt6kKj , but I don't want to make the user authenticate twice (having already done so for the initial mount), and i don't want to make them input some files as relative path, some as HTTPS URL.
I had thought this would be quite like using gspread to work with google sheets that I might have on my locally mounted drive as well. But, I haven't seen this workflow anywhere either. Any pointers in that direction might help me out as well.
Thank you!
Instead of adding .gsheet on colab's drive you can try storing it in the user's drive and later fetch from there when needed. So until that kernel is running you won't have to re-authenticate the user.
I'm also not finding anything to authenticate into colab from other device. So you would consider modifying your flow a bit.

Categories