VS Code Jupyter Notebooks - How to stop result text wrapping? - python

When using Jupyter Notebooks within VS Code is it possible to stop the code cell result text from wrapping?
When querying wide dataframes (Eg 100 columns wide) the resulting text is unreadable due to the text wrapping and requires copying out to other text editors to be able to read the results.
Attached is a screenshot of a simple dataframe header that is wrapping over a couple of lines, once you're returning actual rows it's unusable.
Screenshot

This could be a limitation of Jupyter's UI. I recommend you to see your data in variable explorer and data viewer. By clicking the Variables icon in the top side after running, you'll see a list of the current variables. For additional information of the variables, you can double-click on a row or use the Show variable in data viewer button to see a more detailed view.

Related

How to control result size when using jupyter on vsc and how to search for words in result

I'm currently using Jupytor Notebook on VSC. I found it very uncomfortable when very long result come out because I have to scroll down a long way to go the the next cell, like shown in the picture.
So I was wondering if there is a way to make the result like the original Jupyter Notebook, where they have a separate scroll for the result as shown below.
As an additional question, anyone know how to search for certain words in the result on VSC? ctrl+f only searches for words in the coding cells and not the result.
A work around for the scroll wheel if you don’t want to collapse the code is to add a print statement to the beginning and end of the code block as mentioned in Collapse Output in VS Code Jupyter Into Scrollable Window. I have not been at my computer to test this and this post is from a year ago, so I’m not sure if this solution is still working. EDIT: This solution is no longer working keep an eye on the linked issue for the resolution.
This was also brought up as an issue on GitHub and it was closed saying they have no plans to work on it currently.
#118117
As for the searching in outputs, this is an open issue currently on GitHub: #94239
Scrollable output regions would be handled in VS Code core. This function has not been decided on GitHub at present
For your additional question, I think the filter feature in the search widget might be what you're looking for - you can include outputs with that.

How to display entire output of a code cell when the code is imported from a Python script?

I am plotting some figures using matplotlib inside a notebook in JupyterLab. The code which is plotting these figures is imported from a .py file present in the same directory as of the notebook.
Assuming that figures are of appropriate size, how can I display them entirely i.e. where scrolling is not needed or disabled to display the output and I can get one-shot overview of the output given it is not populating the display beyond the screen size?
The issue is resolved if I copy the code from .py file and run it in the notebook directly:
I have tried Toddneal's answer from Making a Jupyter notebook output cell fullscreen, but scroll bar still exists in the output cell. I also referred to How to avoid output into scrollable frames in jupyter notebook? and tried:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
as the first code cell in the notebook, but gives out the error: Javascript Error: Can't find variable: IPython.
The output cell is already expanded, so the issue is with the height of the output cell. There are bunch of cells beyond the output cells (could that be possibly affecting the height of output cell?). The extension autoscroll might not work because it is a Jupyter Notebook extension:
Due to major differences between the Jupyter Notebook and JupyterLab, the extensions in this repository will not work in JupyterLab.
As krassowki suggested in a comment, the scrolling is disabled by right-clicking on the output cell and choosing "Disable Scrolling for Outputs."

Jupyter Lab, can you stop a cell from showing output in it every time?

So I have been using Spyder for Python, but I end up writing a lot of comments, and the idea of being able to write text in my code without having to comment it out was intriguing to me, so I started trying Jupyter Lab.
I like the cells and whatnot, but I don't want to have the output of my code shown in a new cell below the cell in which I wrote the code. I added an output view pane on the right-hand side, and that shows my output. That's all I want. I don't want it shown in the left-hand pane under the code cell.
However I can't find any way to stop this from happening. I can collapse the unwanted output cell, but then the next time I run my code, it pops up again.
So in the image below, I do want to see all the "{http.." lines on the right, but NOT on the left under the code block.
Any help would be appreciated!! Thanks.

Messaging and Jupyter Notebooks

I'm trying to wrap my head around messaging in Jupyter notebooks. But I'm a bit lost and confused.
My goal is fairly straight forward to state: I want my python kernel to update the output of a cell in a Jupyter notebook while a long calculation is running. Whenever new data arrives in the browser, I want to trigger a redraw by calling some javascript function.
Specifically, the cell output contains HTML with a WebGL canvas. That part works well. I can easily visualize the initial data in the canvas with WebGL/javascript. But I want to update the data dynamically, as the kernel performs a long calculation on it. What I'd like to know is how one of my javascript functions in a notebook can receive binary data from my kernel.
I tried to read the documentation on messaging and jupyter notebooks, but it's really short and doesn't provide any links for further reading. What would really help is an example in the form of two code snippets, one for the notebook and the other for the kernel side.

How to display parsed JSON text

Let me start off by saying that I'm starting this project to get familiar with Python. The project is to parse JSON from Reddit.com every 15 minutes and then display it with Tkinter.
Parsing the JSON text wasn't too difficult, but I'm not sure how display the text. I will need to display two things -- the title of the link and the link -- in a column style view. I was also planning on having two columns side by side to take advantage of the horizontal screen width. I've tried starting out with a Listbox, but that seemed to more be used if you want a selectable list. I just want to display the text and be done with it. Is there a different and more appropriate widget I should be using? I looked into the Entry widget a bit and thought that might be getting closer, but that seemed to only be for storing a single entry.
If you are using a sufficiently modern version of python (2.7, 3....something, I forget) you can use the ttk.Treeview widget which is similar to the listbox but supports multiple columns.
A much simpler choice is to use the text widget. You can insert the text followed by a newline. To line thimgs up in columns just insert a tab, and define an appropriate tab stop.
There are plenty of other options, but those two are arguably the best.
If you haven't dicovered it yet, tkdocs.com has a wealth of information about tkinter.

Categories