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
Related
I'm currently running a default/basic notebook on EMR (Release label: emr-6.1.0, Applications: Spark 3.0.0, Zeppelin 0.9.0, JupyterHub 1.1.0) and i'm having some issues getting the notebook to output a data profiling report in HTML.
I've installed pandas-profiling a variety of ways, using custom bootstrap actions & with the command sc.install_pypi_package("pandas-profiling")
I run into the following issue after trying to generate the report's HTML using IPython. It only produces the object vs the HTML.
I'm also aware that adding %%local can help produce it, like below.
But installing through bootstrap actions/on the notebook does not install from wherever %%local is located. As seen below.
So my first question is, can this profile report be produced without the %%local magic? I know there is also an %%html magic command, but that cannot print out a variable based on my testing, hence why I need IPython.
Second question is, how can pandas-profiling be added to this %%local environment? Should this even be the approach?
Thanks!!
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.
i am working on a project where i have to present the Chart /graph created using matplotlib with python3 into a PDF format. The PDF must carry the data, custom titles along with the chart/graph. PDF can be multiple page report as well. I know that we can store the matplotlib charts in PDF. But i am looking for any solution if we can achieve Data, chart and custom text in PDF format.
Even though the question is not very clear. If I have to do what I understand from your question, I will use Jupyter Notebook and save it as PDF. In this notebook, I will have:
Exploratory analysis of the data (What data scientists call EDA)
Discussion and other mathematical formulas at they may apply to your case
The plots
You can save jupyter notebooks to PDF using nbconvert module in Python.
If you don't have it installed on your computer, do so with this command:
pip install nbconvert
To save your notebook as a PDF, go to the folder containing your Jupyter notebook file and run the following command:
jupyter nbconvert --to pdf MyNotebook.ipynb
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