is there a way to control the layout of jupyter notebook when using it inside pycharm?
currently, I have a side by side display:
is there a way to change it into layout similar to the web's version in jupyter itself?
So that after every input cell, there would be the output of a cell...
thanks!
Not at the moment, unfortunately.
Update 1: PyCharm 2021.3+ has a new browser-like Jupyter layout by default (shared with DataSpell).
Related
I know that I can click on File -> Print Preview and let my browser save the result as a PDF. But that PDF will contain quite a bit of code.
Can I hide parts from the print preview or make a PDF with another tool?
Ideally, there would be magic functions:
%hide: Hide the cell and its output
%hide-code: Hide only the code of the cell, but show the output of the code
Print to PDF in the browser
In JupyterLab, you can hide the cell's input and output by clicking the side bar as demonstrated in the doc. After hiding, you can use the browser's printing menu to generate a PDF. I've tested it on FireFox and expect similar result on Chrome or Edge.
Export to PDF with nbconvert
If you aim at a native conversion from ipynb format to pdf, the nice old nbconvert tool is your friend. It usually comes together with Jupyter and can be invoked conveniently in the menu of JupyterLab File->Export Notebook As...->PDF or, in the classic Jupyter Notebook interface, File->Download as->PDF (via LaTeX).
Hiding input/output in cells can be realized by setting the cell's metadata hide_input=true and installing a nbextension as discussed in issue #155.
Print Preview menu in the classical Jupyter
Finally to your question
Can I hide parts from the print preview or make a PDF with another tool?
The "print preview" button in the classical Jupyter interface is a shortcut for calling nbconvert to generate a HTML file and redirect your browser to it. Therefore, similar configuration for nbconvert to hide input as discussed above (in issue #155) can be used. This feature is implemented by jupyter_contrib_nbextensions bundle and explained in the doc.
As the above-mentioned answers do not work for me; I found another solution:
I use an additional package notebook-as-pdf.
Read the tutorial here. It uses Chromium and is the only approach that worked for me so far reliably. The "print preview" does still not work. But it produces a clean PDF with no code input.
I do:
pip install -U notebook-as-pdf
pyppeteer-install
jupyter nbconvert --to PDFviaHTML --TemplateExporter.exclude_input=True PATH_TO_YOUR_FILE.ipynb
What did NOT work for me:
The solution above.
All the scripts mentioned in those answers
I accidentally pressed some buttons on while I was working on Jupyterbook. Now, each cell shows a 'Run this cell (play button)' icon, which is visually distracting. I cannot find a toggle switch/command to turn it off.
Is there anyway I can turn it off?
You most probably have upgraded the notebook package to the version 5.6.0 or higher.
pip show notebook
or
conda list notebook
will get you the exact version you have.
If the above is the case, unfortunately, your options are limited and are as follows.
Downgrade
pip install notebook==5.5.0
or
conda install notebook==5.5.0
Customize local CSS
Add the following code (сheck out this thread for more flexible and sophisticated solutions) to your custom.css file.
.code_cell .run_this_cell {
display: none;
}
If you're using Conda on Linux you can find the file at (depending on the version of Python you're on)
~/anaconda3/lib/python3.7/site-packages/notebook/static/custom/custom.css
For Conda on Windows try
C:\Users\UserName\Anaconda3\Lib\site-packages\notebook\static\custom\custom.css
Check answers to this question for more details on where the file could be found.
Alternatively, you can create a new file my-custom.css, put it anywhere you want and then reference it from every notebook individually by using IPython's HTML cell magic
%%html
<link rel="stylesheet" href="somewhere-on-your-machine/my-custom.css" />
or explicitly, without needing to create any files
%%html
<style>
.code_cell .run_this_cell {
display: none;
}
</style>
A simpler way of solving this is to select the cells, change them to markdown and then change back to code.
I'm using Jupyterlab for my datascience studies. Everything is Ok with this new tool, but some process as GridSearchCV has long logs and this results pollutes the notebook. There is a way to active scroll bars to avoid this like in traditional Jupyter notebooks?
You have a few options:
Right click on cell's output -> "Enable Scrolling for Outputs". This will limit output view's height and enable scrolling, like in the classic notebook.
Right click on cell's output -> "Create New Output View". This will create a separate scrollable view and dock it to the bottom of the screen. You can then collapse the view in the main window so it doesn't clutter the notebook.
there is an automatic way to do this. First, you must install the addon "Stylus" (available on both Chrome and Firefox). This addon allows you to write custom CSS on websites.
Next, go to your JupyterLab page at localhost:8888/lab and click on the Stylus icon in the top right, and click "Write style for this URL"
Under the URL, i changed localhost to localhost:8888/lab. Then, I copied in this script by user Buckle2000 from Github (https://github.com/jupyterlab/jupyterlab/issues/4028#issuecomment-446820575)
.jp-OutputArea-child {
max-height: 15em;
}
.jp-OutputArea-child .jp-OutputArea-output {
overflow: auto;
}
Then click the Save button, and you should be good to go. I believe you can change the number 15 to make it activate for different heights. It should look like this:
If you are not interested in the output, you can use cell magic capture. It captures cell output and doesn't display them.
Jupyter notebook has a new feature of cell tags since version 5.0 as described in the changelog.
I activated the cell tags going to View > Cell Toolbar as described on their page.
How can I deactivate this little panel on the cells?
Pressing the same button again doesn't help.
Do the same process but this time just click None
If last answer did not help, you also can edit .ipynb file code. in Jupyter - Home-running- stop your file, after that go to the explorer- click right bottom on your_file.ipynb open with notebook(just like .txt) - scroll down, find raw with "celltoolbar": "None", and delete this and save file, after run file in jupyter.
Is there a method to exclude some cells from the NBconvert process
For instance. An embedded video is cool when running to HTML, but when converting the HTML to PDF it creates a problem. So I want to exclude it in some instances.
Found a nice workaround for this, using the 'slides' option of nbconvert:
In your iPython notebook under "Cell Toolbar" select "Slideshow"
Then in the top right of the cells that you don't want to show select Slide Type "skip"
Now run python nbconvert your_notebook.ipynb --to slides
Instead of serving the slide, just open the resulting html in a browser.
And.. It doesn't contain the slides you told it to skip!
Hope this helps.