Google Drive does not recognise .ipynb file as colab notebook - jupyter-notebook

If I create a new Colab notebook in Google Drive, it is recognised as a Colab notebook.
If I upload a .ipynb file into Google Drive, it is not recognised as a Colab notebook.
In the example below, file1.ipynb was created in Google Drive (and is recognised). This file was then downloaded, renamed to file2.ipynb, and then uploaded. The duplicate is not recognised (but you can open and run it in Colab, so the file is OK).
What could be wrong?
The JSON in the .ipynb file that is recognised, and the copy that is downloaded and then uploaded is identical.

As mentioned before, Google Colab usually recognizes the .ipynb files that created within itself. Uploading directly to Google Drive or even inside the folder "Colab Notebooks" doesnt't work.
But there is a way to upload .ipynb files to Colab;
Open https://colab.research.google.com
Go to File > Upload Notebook
Notebooks that uploaded with this method will be shown as Colab files in your drive as well, even if you change the location.

I have created a new empty Colab file. Download it. Then upload it to Google Drive again.
The content of the new file and the uploaded file is the same. But the displayed logo is different. So it's not about the content. Google must be tracking which file it create itself from its system, and which file is uploaded.
So, I think it's impossible to find a way to create an ipynb file that will be recognized as Colab.

Related

Is it possible to edit a csv in colab after it has been uploaded

I want to make changes to the csv file without having to do it on local and upload once again. Is it possible to do so?

How to upload ipynb with images in it's markdown cells to google colab

I want to upload an .ipynb which has images in it's markdown cells, but when I upload it to google colab it doesn't show the images. I tried uploading the file solely and with it's '.ipynb_checkpoints' folder and in both cases problem was there.
probably the reason is the way colab saves images in it's cell(image and data in the same place something like this)
but jupyter-notebook on windows saves the image on cell like this
so how can I upload an .ipynb which has images in it's markdown cells from pc to google colab? by the way the answer is not probably in this link How to embed image or picture in jupyter notebook, either from a local machine or from a web resource? and also I know when I open the .ipynb in text(notepad) I can access the data (=in the way colab saves the image) but I don't want to copy and paste 100s of images manually.

Is there a way to download data from a public link to google colab?

I am currently working with a Jupyter file on google colab with 5000 images and several csv files. I wish to find a way to download these data into the colab from a shareable link from google drive without mount to drive, which is: I upload these data into drive first and make them "anyone can view with link", and then I wish to find a way to download these data into colab with this link (So that others can simply run my code without authorization or mount to drive)
Is there any way I can achieve this? Thank you!
You can use gdown.
For example, an image url
https://drive.google.com/file/d/1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT/view?usp=sharing
It's id = 1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT
So, you can download it with
!gdown --id 1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT
you can use !wget in colab to download .csv file in your runtime storage
For Example
this is public link for google sheet
https://docs.google.com/spreadsheets/d/FILE_ID/edit?usp=sharing
we need to get download url for this google sheet file
follow link to get download link
Creating a link to download whole spreadsheet from Google Drive
now we got download url in this form
https://docs.google.com/spreadsheets/d/FILE_ID/export?
type this code in colab
!wget https://docs.google.com/spreadsheets/d/FILE_ID/export?
file will be downloaded like this
snap shot from colab
rename file as your choice
rename snapshot
finally import it using
df = pd.read_csv("/content/file.csv")

How to open an external file from a Colab Jupyter notebook?

I have a Jupyter notebook in which I create an HTML file. I then open this HTML file in a new browser tab.
It's an R analysis, so I opened the HTML file using browseURL().
However, when I use a Colab hosted version of the notebook, nothing happens when I try to open the page.
Here's a reproducible example: https://colab.research.google.com/drive/1BfVDsDnXQwEpy4HwPKWkUC9Bpaz6r0Kv
Other things I tried that didn't work:
Using system2() instead of browseURL().
Setting the browser option to the open system tool via options(browser = "/usr/bin/open").
Is there another value for browser I should use? Is there a permission setting I should change?
Otherwise, how can I get the Colab notebook to display the HTML page I created?
As far as I know, Colab stores its files in Google Drive and judging by this link, Google doesn't support serving HTML from there.
You could save them as png files and display them like this if you're OK to have to install a few extra libraries.
install.packages('webshot')
webshot::install_phantomjs()
library(webshot)
webshot('https://www.halfbakery.com/', 'hb.png', delay = 2)
install.packages("png")
library(png)
img <- readPNG('hb.png')
grid::grid.raster(img)
I have tried it in Colab and it works there. I should add that browseURL still doesn't work on the file although double clicking on the file in the Files page does bring up a window with the png correctly displayed.

Upload any file to ipython notebook directory

I have the following line on the notebook home page:
To import a notebook, drag the file onto the listing below or click here.
When I upload a text or any other file, I get an error message:
Invalid file type
Uploaded notebooks must be .ipynb files
How do I make it possible to upload any file ?
Is there any setting/ add on that will allow this?
This is now implemented on master (futur 3.0), we now have the content webservice which can deal with non-ipynb file. Just drag file onto the dashboard and it works(tm).
Keep in mind that this upload on the machine were the webserver is, not the machines were the kernels run in case they are not the same.

Resources