Adjust the height of individual jupyter notebook cells - jupyter-notebook

The custom.css works very well for adjusting the width of a jupyter notebook (and the font size while we are at it..):
.container { width:100% !important; height: 200px; }
.CodeMirror pre {font-family: Monaco; font-size: 9pt;}
The cell height is trickier however since we do not want all cells to be made overly tall.
Here is an example of a cell "wanting" more vertical headroom:
Is there a per-cell approach to achieve this? There are actually two parts to this question:
How to do this for python kernels (probably the easiest):
How to change the cell height for other kernels: specifically we are interested in R and Spark

It's a little hacky, but the python flavor of this can be done using jquery and some IPython functions that let you execute javascript inline within a cell.
from IPython.display import display, HTML
This will let you execute javascript from anywhere in any cell like this:
display(HTML("<script>alert('Hello, World!');</script>"))
Then we mix that with some jquery and a few known classes that are on Jupyter div elements and we can change the output_wrapper size of the executed cell to whatever it needs to be:
display(HTML("<script>$('div.cell.selected').children('div.output_wrapper').height(50);</script>"))
If you don't want to re-run the code in that cell again, insert a cell above the one you want to change and tweak it to select the next cell div and update the height:
display(HTML("<script>$('div.cell.selected').next().height(100);</script>"))
Wrapping these with helper functions would be easy and worth while if it was needed on multiple cells.
This obviously won't be kept when the notebook is closed or reloaded. For that, you could improve this by adding a cell metadata attribute, then put something in the custom.js that reads and renders as needed.

Related

NG Zorro Multi Select - keep selected items on one line instead of wrapping and doubling height

Anyone know if there is a way to make the ng zorro select (multi) to stick to one line instead of wrapping the selected items. In some scenarios its fine but when you have certain layouts you cant have the height doubling on each selection.
There is a codebox demo here: https://codesandbox.io/s/2lp2n (reduce the size of the view panel to see what i mean).
I have tried pretty much all i can think of (adding css to the select and select top classes to try and force it to stay on one line but it doesnt seem to work). I wanted to ask here first to see if anyone has any ideas since their git would normally close a question and ask me to come here first.
Thanks
In the end i just had to add:
flex-wrap: nowrap !important;
to nz-select-top-control

Make cell output in Jupyter notebook scroll horizontally?

I have a long Sympy expression that I'd like to get printed with a horizontal scrollbar beneath it. Is it possible to do so in Jupyter? I'm able to toggle vertical scrolling but I want it to be horizontally scrollable instead. The problem with vertical scrolling is that the output of sympy.pretty_print() gets badly distorted in my case. The output also looks ugly and the user has to scroll through the whole output unnecessarily.
Something similar to the np.set_printoptions(linewidth=some_large_number) and/or np.set_printoptions(threshold=some_large_number) approach can be useful but doesn't fix the problem if Jupyter's output window is itself too narrow.
The quickest solution I ended up with is inserting this line somewhere at the top of your notebook:
from IPython.display import display, HTML
display(HTML("<style>pre { white-space: pre !important; }</style>"))
If you want to change this setting for all of your notebooks, you'll need to mess around with the custom.css config file for Jupyter as discussed here.
I wasted too much time figuring this out. Hopefully I can help some of you figure it out quicker!
Iterating on Eric's response slightly, here's a self-contained version that only creates horizontally-scrolling outputs when you want it to, rather than enabling it notebook-wide:
from IPython.display import display, HTML
from pprint import pformat
def boxprint(*args):
for arg in args:
display(HTML('<pre style="white-space: pre !important;">{}</pre>'.format(pformat(arg))))
As written by Eric, changing the white-space property to pre prevents automatic wrapping of output cells, and thus forces an horizontal scrollbar for all wide outputs of the current notebook.
Unfortunately, changing this property also prevents automatic wrapping when editing input cells, which is particularly annoying when editing markdown cells. Even worse: this behavior is not limited to the current notebook, but happens on all open tabs when using JupyterLab, for instance.
The workaround I propose, is to define a function to switch between the standard behavior white-space: pre-wrap and the scrollbar behavior white-space:pre. This simple function does the job:
def hscroll(activate=True):
"""activate/deactivate horizontal scrolling for wide output cells"""
from IPython.display import display, HTML
style = ('pre-wrap','pre')[activate] # select white-space style
display(HTML("<style>pre {white-space: %s !important}</style>" % style))
On hovering right below
out[]:
in notebook you see "scroll output" . On clicking anywhere in that area you get your output scrollable both horizontally and vertically.

How do I change Atom's bottom window height?

I recently started using Atom and try to make it as nice to work with as possible.
However I couldn't figure out how to change the height of the bottom window (a name for it would already help).
My goal is to have my console etc. as minimalistic as possible.
E.g.:
Atom's bottom window shown here with an output example from Atom-Runner
How do I only show the atom-runner's output and not the grey rest of the window on top of it?
How can I get rid of unnecessary labels like "Atom Runner: data.py"?
I found that you can change quite a bit within the styles.less file with commands like:
atom-workspace {
height: calc(...);
}
But that didn't really help me.
However I couldn't figure out how to change the height of the bottom window (a name for it would already help).
atom-runner displays its results in a bottom panel. There are a few different types of containers in the Atom window:
Panes are the content in the middle of the editor. Panes can hold as many items as you want, which are usually associated with a specific file (see TextEditors)
Docks are the expandable areas just outside the panes (the tree-view and github packages use docks). They can have multiple items and will create tabs for them.
Panels are the spaces on the edge of the Atom window. You can't hide them without disabling the whole package.
How do I only show the atom-runner's output and not the grey rest of the window on top of it?
The "grey rest of the window" is the bottom dock. You can hide it by clicking on the semicircle with the down arrow.
How can I get rid of unnecessary labels like "Atom Runner: data.py"?
I disagree that it's unnecessary, and you might some day find that you need to know what file you ran. However, if you want to do this, you can add the following to your styles.less:
.atom-runner h1 {
display: none;
}

Dynamic table-width doesn't adjust properly

I'm trying to build a genealogy tree with HTML tables (and nested tables). It should, ultimately be editable by the user using contenteditable, and the nested cells should resize accordingly.
However, to my mystery, when I edit the cells, they resize far too fast and too much. Why so?
The outer table keeps everything under control, so sizes are fixed using
table-layout:fixed;
The nested table cells, on the other hand are only specified via
margin:auto;
Every cell's width is set individually via percentage, and it looks perfect before editing. Not so after.
DEMO here http://jsfiddle.net/KtB6C/
Try editing the Father or Mother cell.
I know this is a "fix-my-code" problem, but any help is appreciated.

Completely remove sidebar from MediaWiki

How do I completely remove the sidebar from MediaWiki, and I mean in the sense that the content div occupies 100% of the width of the browser space? I've successfully implemented an extension where non-registered users do not have a sidebar or toolbox to begin with and hence the extra space now seems rather superfluous in such cases.
I'm trying to create my own skin from Vector and have tried so far to change the margin-left: 10em and corresponding tags in div#content and mw-panel in the skin's css file but no luck so far.
Why use CSS when you can edit the sidebar menu and have this stored in the database
Navigate to MediaWiki:Sidebar edit the page and remove the components you don't need
If you want to use CSS then you can try,
#sidebar{
display:none;
}
to see if it gives you the desired effect.
Or you can do what dreamweiver said and use JQuery
$('#side-bar').remove()
If, as you are writing, you are creating your own skin, then you simply do not have to print the sidebar! It is there because you have a piece of code in your skin printing it.
Search your skin code for $this->data['sidebar'], and you will find the loop that prints the sidebar.
However, I'm guessing that you skin has some kind of navigation,and rather than reinventing the wheel, I would recommend using the sidebar, with it's built-in functionality (possible to set from MediaWiki:Sidebar, etc), even if you chose to use it in another fashion. it doesn't have to be printed as a sidebar,just because that's the name -- it could be a top menu, a dropdown, ...

Resources