.ipynb file not displaying properly in GitHub - python

I've uploaded a .ipynb jupyter notebook in GitHub but it doesn't display the exact same output as I've written in jupyter notebook.
Here's the link to my repo: ipynb file

You need to view the notebook as "rendered blob" not as "source blob". In GitHub, this is done by selecting the second rendering option in the top right:

It is mostly issue with Github backend. Try this way instead uploading directly
Go to --> https://nbviewer.org/
Paste your .ipynb github link here.
You can downlaod or embedded your file directly from here..

Related

View Jupyter notebooks hosted on Sharepoint

In our institute, we use OneDrive / Sharepoint from Microsoft to share files with each other. I am also sharing my Jupyter notebooks - with extension *.ipynb - there. Unfortunately, when one clicks on such a file the message "Hmm... looks like this file doesn't have a preview we can show you" appears. In my case I developed my notebooks with python. It's not necessary that my colleagues can run the notebook, but it would indeed be much easier to be able to install a kind of plugin for previewing on the Sharepoint server. Is there any product that can work like this? Otherwise I'll have to always export the file to HTML or so :-(
Unfortunately, there isn't any good news so far. Such a plugin seems to be unavailable as yet. For the meantime, I have automated the exporting of the notebooks to HTML on my Windows 10 machine as follows:
For /R .\ %G IN (*.ipynb) do jupyter nbconvert --to html "%G"
For use in a *.bat file, you'll have to double the %-signs.

How to export Jupyter Notebook to html with line numbers in code cells

I have been searching unsuccessfully for information on how to export jupyter notebooks to html with code lines numbered.
Is this possible?
Thanks
This was solved in this issue of the ipython GitHub repository.
Basically nbconvert hasn't got a setting for this, but you can create a custom template to get the result you need.

Convert ipynb notebook to HTML in Google Colab

I have a Google Colaboratory Notebook for Data Analysis that I want to output as a HTML file as currently not everything loads within the Colab environment such as large Folium Heatmaps. Is it possible to export the notebook as a html file as opposed to the ipynb and py options?
Method using Google Colab only
Download your .ipynb file
You can actually do it using only Google Colab. File -> Download .ipynb
Reupload it so Colab can see it
Click on the Files icon on the far left:
Then Upload to session storage:
Select & upload your .ipynb file you just downloaded.
Get your file's path
then obtain its path (you might need to hit the Refresh button before your file shows up):
Conversion using %%shell
Then, just as in Julio's answer, execute in a Colab cell:
%%shell
jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb
The %%shell lets the interpreter know that the following script is interpreted as shell. Don't write anything before %%shell, use a distinct cell for this.
The form of /PATH/TO/YOUR/NOTEBOOKFILE.ipynb will be something like /content/lightaberration3.ipynb.
Your file is ready
Might need to click Refresh again, but your notebook.html will appear in the files, so you can download it:
The great thing about this is that nothing python-related has to be installed on your computer, not conda, not pip, only a browser.
Google Colab doesn't currently have such a feature as a built-in.
Your best route is to first download it through File > Download .ipynb and then use the standard tool for Jupyter Notebook conversion, nbconvert:
jupyter nbconvert --to html notebook.ipynb
If you use an Anaconda Python distribution, nbconvert is most likely already installed. If not, refer to what is described in their install instructions to be able to convert:
pip install nbconvert
# OR
conda install nbconvert
to continue with "Method using only Google Colab"
" %%shell jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb" - as given
the following worked for me - type the following in Google Colab
!pip install nbconvert
%shell jupyter nbconvert --to html /content/testfile.ipynb
(instead of using %%shell in Google Colab, use %shell - this way, it worked for me)
Download your notebook and upload it back to the colab
Replace PATH_TO_THE_NOTEBOOK_IN_COLAB in the below command to the location of the reuploaded notebook.
Use this command to download the notebook as html => !jupyter nbconvert --to html PATH_TO_THE_NOTEBOOK_IN_COLAB.ipynb.
I tried the approach above but couldn't get it to work - for small jobs I log onto https://jupyter.org/try , upload the downloaded ipynb file from Google Colab and then I opened the file, from here you will have the functionality in jupyter.org to download as html or whatever other format you require. It took the pain out of trying to get it to work.

How to embed pdfs files in jupyter notebook on Github

So I have few pdfs files which I uploaded to my repository on Github. Now I am uploding a jupyter notebook file in the same directory as the pdf files on github and want to display pdfs inside the jupyter notebook.
I used the following method to embed pdfs in a notebook.
from IPython.display import IFrame
IFrame("https://github.com/user/first.pdf", width=900, height=800)
Now the same thing works when I do this on my local laptop where I store the pdfs in a directory and link that to the jupyter notebook file on my laptop. I can see the pdfs inline too.
However when I do the same thing on Github, it doesn't show the pdfs and get the following thing:
So am not sure why it is not able to link the pdfs stored on the same repository on github and display them while it works on my local system
Any help?
Thanks
In the case of Github, it is because of X-Frame-Options restriction.
See: iframe not rendering in ipython-notebook
As a workaround, you can try using rawgit.com:
Example:
https://raw.githubusercontent.com/mozilla/pdf.js/raw/master/test/pdfs/S2.pdf (does not work)
https://rawgit.com/mozilla/pdf.js/master/test/pdfs/S2.pdf (works)

Open IPython notebooks (*.ipynb) in read-only view (like a HTML file)

Nowadays with more and more IPython notebook files (*.ipynb) around, it is very disturbing every time when I want to peek at some notebook I have to open a server for it, and cannot do it in read-only mode. Due to auto-save I can accidentally change the file when reading it if not in read-only mode.
I hope something like this: ipython notebook mynb.ipynb --read-only would work, but sadly it doesn't (although still it creates a server which I don't really want in read-only view). What I really want is to open an ipynb file like a HTML file for reading; currently it seems a missing view of ipynb file, and now the notebook is more like a black-box or near-binary file alone.
(P.S. I am using Linux/Ubuntu.)
When you change the notebook files' permissions, jupyter's auto-save doesn't touch them:
chmod a-w *.ipynb
Then jupyter goes into read-only mode:
Try this ipynb Viewer. This renders ipython notebook as a static web-page.
Also ypu can convert ipyhton notebook to other formats using
ipython nbconvert --to FORMAT notebook.ipynb.
Refer Convert Ipython notebook to other formats. Using this you can convert ipython notebook to HTML.
You may also want to try nteract app (https://nteract.io)
nteract is a desktop application that allows you to develop rich documents that contain prose, executable code (in almost any language!), and images.
Here you can find more detailed review of the app.
It is completely free and very convenient tool by itself and I use it quite often to see other ipynb files if needed and for quick development.
The best I can suggest - unfortunately still a bit verbose - is using nbconvert to create a HTML version of the file, then opening it with your browser. Below are commands to do this (assuming that your browser is set up as the default program to handle .html files). Just replace yournotebook.ipynb with your real Notebook name.
Linux
jupyter nbconvert --to html yournotebook.ipynb --output /tmp/notebook.html &&
xdg-open /tmp/notebook.html
macOS
jupyter nbconvert --to html yournotebook.ipynb --output /tmp/notebook.html &&
open /tmp/notebook.html
Windows
jupyter nbconvert --to html yournotebook.ipynb --output "%TEMP%\notebook.html" && start "" "%TEMP%\notebook.html"
(Note that if you want to do this in bulk, perhaps in a loop in a script, you'll probably want to modify the commands above to not always use the same filename for the HTML file, to avoid the race condition where the HTML file has been overwritten by the time the browser actually gets round to starting to read it.)
Intellij IDEA (which is also available as free open-source community edition) can render ipynb files as well. In fact it also allows to author notebooks, so it's not just a viewer.
It can be used via file type associations or via the command line launcher (e.g. idea foo.pynb).
I use Github Gist for that. You'll need a Github account.
If you specify *.ipynb file extension there for your content copy/paste, it'll detect it and format as html view. You'll be able even sharing it with someone using link if that's interesting. No tools required other than having a browser.
I've found some glitches in formatting though, mostly with output plots, but it's reasonably rare.
Random example here: https://gist.github.com/Clockware/aa7e01722579841d5888ca83385a5f1d
I was able to read .ipynb files as html in visual code. You would need a python plugin for it which visual code auto detects. Fairly straight forward after that.
This most convenient method to take a peek at jupyter notebooks is by using nb-viewer, with this utility, you will be able to open notebooks (in read-only mode) with a double click.

Categories

Resources