Jupyter Notebook cell stopped working as such - jupyter-notebook

There is the first cell that is supposed to execute code as the rest, but somehow it's not even working at all.
The next cells are working properly, but this forst one doesn't recognize my input.
In the pictures provided you can see that the next cell recognizes my input as code and highlights the proper words in color. When I first opened the notebook it was alright, but it just stopped working for this first cell.
I have tried to close and reopen, interrupt kernel and everything in my hands.
Thank you very much for your time.

Cell was not stuck on an infinite loop. Somehow Jupyter Notebook stopped recognizing it as a code cell. Therefore you have to manually srt it back to code cell. See image.

Related

Chunk does not display executed code result/plot in R

Chunk output inline setting not working.
I started R for my daily work, and when ran a code (simply display a subset of a data frame) nothing is shown, neither inline nor on the console or viewer. I have set absolutely nothing differently, didn't even touch the settings. It says "Chunk output inline" anyway.
It was working normally for a year, and now from a day to the other, this happens. If I execute the subsetting in the console, then it displays the subset in the console. But if I execute in the chunk, no displaying anywhere.
Thanks in advance

How to save full console OUTPUT in R every time RStudio is exited?

The title says it all.
Tried history() and it only went back very few lines, but I want to see my progress from the first lines of the project.
How can console in R be saved so that everytime it opens where things were left off?

How to increase the amount of lines you can read in R's view()

In an RMarkdown file, you can see the below sample text in red. It prints in the console and the RStudio Notebook Output (using view()) up to 10,000 lines after running my code.
However, the total text is 20,000 lines long. I can't find help online which indicates how to increase the number of lines you can view in R and I need to access all of it. Can anyone help? I want to view all of the text basically.
Note that my code took hours to run, RStudio crashed when the code finished executing, and the information I need is saved in red. Hence, I can't re-run the code without the same problem occurring.

How can I reduce the file size of my iPython notebook?

I have an IPython notebook which is several megabytes big although the code inside is just about 100 lines. I think it is that huge because I load several images inside.
I would like to add this notebook to a git repository. However, I don't want to upload something that big which can easily be generated again.
Is it possible to save just the code of an IPython notebook to reduce its size?
You can try following steps since it worked for me:
Select the "Cell" -> then select "All Outputs" -> There you will find "Clear" option select that.
And then save the file.
This will reduce the size of your file (From MBs to kbs). It will also reduce the time to load the notebook next time you open it in your browser.
As per my understanding this will clear all the output created after execution of the code. Since Notebook is holding code+images+comments in addition to this its also holding the out put in that file therefore it will increase the size of the notebook.
I run into the exact same problem with one of my notebooks, which I solved by changing my df to df.head(5). I did this instead of clearing all outputs as I still wanted to show on GitHub how my code changed data inside the columns in my df.
You also can run !ls -lh in the last cell of your notebook to check size of your notebook before saving. This will give you an idea if you need to clear outputs/replace df with df.head()/remove images in order to reduce the size and be able to save on the GitHub.
Now you generate a simple script linked to the notebook with jupytext which others can rerun.
If you need to keep the images within (because, for example, you are sharing the notebook with someone who does not want to/can not rerun it) you might want to try to reduce the images.
I found this module ipynbcompress which seems to do exactly this, but so far I could not install it.

How to load a notebook without the outputs?

I mistakenly printed to much to the output during a single cell's execution and now the browser tab completely freezes every time that notebook is opened. I tried restarting ipython and it didn't help (I am guessing that each time it is loaded, also all the chunk of text is loaded with it).
Is there a way to load a notebook with outputs suspended or clear?
One hack if you're desperate: open the .ipynb file, which is a text file. Scroll down to the lengthy cell output and delete it. Of course, you need to be careful that the result is still a valid .ipynb file.
nbstripout is a simple tool that removes all output from a notebook (without needing to open the notebook in your browser).
your code will be saved in the form of JSON. open it with json viewer and carefully delete the unwanted output cell and save it back.

Resources