Jupyter notebook: run code of exported file (e.g. HTML) - jupyter-notebook

I wonder if it is possible to run code in an exported HTML file by "jupyter" notebook?
I am trying to make an online website for a tutorial of PariGP

Related

How can I open an R Markdown file from GitHub in Google Colab?

I´d like to create links for R markdown files (.Rmd) in a GitHub repo so that these directly open in Google Colab.
I can do this with Python Jupyter notebooks. However, I haven't found any way to achieve the same with R Markdown files.
How can I do this?
Thanks for any help or pointer in the right direction.
PS: One of the few hints I found online mentions this link format, which unfortunately doesn't work:
https://colab.research.google.com/github/<GITHUB ACCOUNT NAME>/<REPO NAME>/blob/master/example.Rmd
Colab yields this error message:
Notebook loading error
The file has been corrupted or is not a valid notebook file.
However, the notebooks that I tested work properly on any other platform, e.g. RStudio etc.

Open jupyter notebook from .py in pycharm

I am using Pycharm 2021.2.3 pro.
Is it possible to open a .py file as a jupyter notebook from within pycharm?
In the classical jupyter notebook, it is possible to open a .py file as a notebook and work with it like with a classical .ipynb (adding markdown etc.).
This allows to work on the full notebook without worrying about cells ordering like with a classical python script. When the script is ready, it is then possible to switch to the notebook view with its nice presentation features.
we did this when creating dash apps, you make the .py file upload and refer to it by way of importing as we do with regular python libraries

How can i edit jupyter notebook from terminal without opening web browser?

How can I edit my jupyter notebook in terminal.
I just don't like to open jupyter notebook in web browser.
I google out but every answer is related to how can we open notebook from terminal directly.
I'd suggest looking at Jupytext's ability to do command line conversions back-and-forth from the notebook json structure to a python script (or markdown). If you already have the backbone of a notebook (.ipynb) file, you can convert it to .py script using jupytext --to py notebook.ipynb. That makes a text file that is easy to edit in your favorite terminal based text editor. The json in the .ipynb files is not as easy to edit directly.
Then when you are done editing, you can convert the .py script form back to a notebook with something like jupytext --to notebook notebook.py. Optionally, you can even execute it without opening a browser by adding --execute. I have an example conversion-and-execution command in use here.

Jupyter Notebook - .ipynb files - opening as plain text - No longer interactive notebook

I have a Windows 10 machine with VirtualBox, Linux Mint 18, running Jupyter Notebook.
I have successfully generated 20+ notebooks and viewed them running html, and processed still images.
I changed the viewer to view the source code of the page, and cannot figure out how to switch back to the notebook view.
Now when I click on my .ipynb files, I see the plain text, but no longer am viewing the file as an interactive Jupyter notebook.
I've tried changing the lower bar setting to JSON and HTML, but that does not seem to correct the problem.
Ahhh, Jupyter notebook was not running when I clicked on the .ipynb file.
Because the .ipynb files are stored in plain text format, Mint just opened the file as plain text, rather than giving me an error message saying "cannot open .ipynb files."
PROBLEM SOLVED

Cannot import .py file to ipython notebook

With apologies in advance for the "I can't get it to work" question: How should I load a .py file into ipython notebook? I want to convert python code to notebooks (first simple scripts and later scripts that include nbconvert directives embedded as comments-- see bottom of the linked file.)
Perhaps I'm doing it wrong, but perhaps there's something wrong with my set-up. When I drag a .py file to the Notebook's file list, I get the message
Invalid file type: Uploaded notebooks must be .ipynb files.
I even tried changing the extension to .ipynb (keeping the python script unmodified); reasonably enough, I got an error:
Error loading notebook: Bad request
Any idea what's going wrong?
System information: I'm on OS X (10.8, Mountain Lion), using Firefox 28.0 and Anaconda 1.9.2 (x86_64), which supplies python 2.7.6 and ipython 2.0. Anaconda is not on the default PATH; I add it in a bash session from which I then launch notebook with ipython notebook, and I'm able to open and edit .ipynb files normally in the browser.
But I do get some curious behavior:
When exporting from notebook as a .py file, I don't get the control comments documented here but a simpler format, without version number:
# coding: utf-8
# In[ ]:
print "This is a slide"
## Top-level title
### Second-level heading
#### Third-level heading
# This is some `markdown` text.
#
# And some more here.
Any idea what's going on here?
The same format is generated by ipython nbconvert. However, if I start the notebook server with ipython notebook --script (which exports the notebook as a python script every time it is saved), the result contains the nbconvert directives we need to convert back to a notebook!
I had the same problem.
This post helped:
How to load/edit/run/save text files (.py) into an IPython notebook cell?
Basically, we just have to use the following command in the cell. And the .py file has to be in the same directory.
%load filename.py
I'm not sure why notebook doesn't support this natively, but I've concluded that the answer is: It can't be done from the command line or notebook GUI.
Control comments like <markdowncell> can only be interpreted by accessing notebook's API through python, as shown by #CliffordVienna in this answer to my related question.
import IPython.nbformat.current as nbf
nb = nbf.read(open('test.py', 'r'), 'py')
nbf.write(nb, open('test.ipynb', 'w'), 'ipynb')
Edit: The above method does not work with the current version (v4) of the Notebook API, so I have added this self-answer to show how it's done.
If you only need to import a local file, first use:
sys.path.append(os.getcwd())
to place the .pynb file's directory in sys.path, and then import the local file.

Resources