I am using jupyter notebook on my PC. As the length of my codes is increasing, I want to hide and display some sections of the python code based on the heading markings in Jupyter Notebook like the google colab does.
Is there any python package to install in the environment specifically for this functionality? Similar to the screenshots below.
Hidden Codes based on the headings
[1]: https://i.stack.imgur.com/kQSMG.png
Expanded Python Codes
[2]: https://i.stack.imgur.com/20HNw.png
I am using Jupyter lab, everything works fine within jupyter lab even when I am offline. However whenever I try to export the report to HTML. the plotly plots are not rendered. If I turn on my internet connection the plots are rendered, just fine.
Here is a sample code:
import pandas as pd
import numpy as np
import plotly.express as px
df = pd.DataFrame(np.random.randn(100,4), columns='A B C D'.split())
px.scatter(df, x='A',y='B')
I have tried following the troubleshooting guide for plotly shown here. Additionally I tried installing on a fresh environment.
If i use the following:
import plotly.io as pio
pio.renderers.default = "jupyterlab"
The offline HTML includes static plot, however I would very like to have the interactivity enabled.
I have noticed that the files differs in size, the static pages are only around 700 Kb whereas when I try to save them as interactive they are about 4 Mb.
Is this not possible in Jupyter lab ? or am I missing something
If you want to be able to have interactivity while being offline, you need to add the plotly.js to the output html.
You can achieve that like this:
import plotly.io as pio
pio.renderers.default='notebook'
Actually, this should be done by default on JupyterLab (you can tell be the increased file size. As in your case it will be >4MB). So if that doesn't work, I suspect a bug. I think I've experienced something similar. Here's my browser console output when using your example and exporting it to html:
For some reason, the included plotly.js seems to depend on require.js which is not included in the html export for some reason. Instead, your page will try to load it from a CDN which fails when you are offline (as seen in the screenshot).
Now, what you can do is to manually include a local version of require.js. Get a copy here. Then, in your Notebook add the following at the top:
%%HTML
<script src="require.js"></script>
Then, export your notebook to html. Make sure, it is in the same folder as the require.js file you downloaded before and open it in the browser.
There should be no more error message in the console and your chart should appear and work interactively:
/e: If you want to share your notebook, this might be sub optimal as it requires you to also distribute the require.js script. You can also directly include the whole script in your notebook. Just put the %%js cell magic at the top of a code cell and paste the content of the require.js file you downloaded below that.
As you are trying to export it to HTML, don't forget jupyter's way (.html). Also with the "Open with" button on jupyter, you can see the maximum file size that it can handle. And most likely the storage wouldn't be the issue.
Is there a way to customize jupyter notebooks in pdf format ?
I understand using : jupyter nbconvert
_file=./revtex_nocode.tplx myfile.ipynb , and revtex_nocode contains the customizing code.
However is there any standard file available for the same ? if not can some one help me with basic customization in it ?
I would like to export a jupyter notebook to html or ipynb to display online (e.g. Github). My notebook produces some images with matplotlib, and I would like a static version of these images to be included. I've seen several examples of this, and they all seem to use the inline option:
%matplotlib inline
I've tested my code with this option and the images are saved fine (either in the exported html or using an online viewer). However, when I use the ipympl or notebook backends (to keep some interactive features) the images are not saved. Is it possible to include them in the exported html or ipynb?
One of the main advantages of using Jupyter is the ability to code and document in the same time. Many times, I use headings and subheadings to group the code in a notebook. However, as the notebook gets longer, navigation becomes much harder.
It would be nice to have a document map in a separate (left) pane that keeps track of the markdown headings. Once a heading is selected in the document map, the respective section would appear in the main pane.
Is there an extension for this task?
I cannot comment on your question (low points) so if the answer is a bit off...
I've found an extension that looks like what you need
src: https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/toc2
Documentation: http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/toc2/README.html
Another, not that good:
(imho) https://github.com/captainsafia/notebook-toc
Possible duplicate of: How can I add a table of contents to an ipython notebook?
EDIT
Install instructions:
Toc2 is included in: https://github.com/ipython-contrib/jupyter_contrib_nbextensions
to install just TOC2 i did this:
pip3 install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextension enable toc2/main
EDIT 2
How to display the TOC inside a notebook: http://awesomescreenshot.com/0116cqvh5b