82

In iPython Notebook, is it possible to disable the autoscrolling of long outputs? Or at least set a threshold for the output length before autoscrolling sets in?

Tried the following command

%%javascript
IPython.OutputArea.auto_scroll_threshold = 9999;

but it gives an error

Javascript error adding output!
SyntaxError: Unexpected identifier
See your browser Javascript console for more details.
1
  • 4
    You may be able to edit the config file... In the meantime, if you click on the side of the result bar, it will rotate from autoscroll to expanded to hidden. Apr 21, 2016 at 0:15

8 Answers 8

105

Can also be done via user interface.

  • Individual cells: Cell->Current Outputs->Toggle Scrolling
  • All cells: Cell->All Outputs->Toggle Scrolling

enter image description here

2
  • 5
    The problem with this answer is that you have to do this every time you execute, it is not permanent Oct 23, 2020 at 8:09
  • 1
    This does not work for JupyterLab because there is no Current Outputs menu. Jun 26, 2022 at 0:00
85

To disable auto-scrolling, execute this javascript in a notebook cell before other cells are executed:

%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}

There is also an ipython notebook extension, disable_autoscroll, you can use for a more permanent change. Follow ipython issue #2172 for the latest details.

3
  • This doesn't work for me, when I run this, I get the same error as OP.
    – frmsaul
    May 25, 2017 at 23:48
  • @frmsaul what version of IPython notebook are you using? Still works for me in jupyter notebook 5.x (and 4.x).
    – mtd
    Jun 15, 2017 at 1:33
  • 1
    Great, still works with current nbclassic notebook! Dec 13, 2022 at 8:42
10

To prevent scrolling within a single cell output, select the cell and press Shift+O while in command state. It will toggle output for that particular cell. If you want all the cells to display long outputs without scrolling, then go to the Cell tab -> All Outputs -> Toggle Scrolling. That's it !!!

2
  • 1
    This should be the answer to this ask.
    – SouravOrii
    Dec 2, 2021 at 4:02
  • 2
    You have to do this each time you run a notebook. The OP is asking about making it permanent.
    – user5054
    May 13, 2022 at 15:16
6

This works for me (with no semicolon)

    %%javascript
    IPython.OutputArea.auto_scroll_threshold = 9999
2
  • Can you explain a bit more? Oct 25, 2019 at 12:52
  • When I remove the semicolon at the end (after 9999) I don't get the error anymore Oct 26, 2019 at 15:48
3

To disable scroll to bottom after run all command, execute this code:

%%javascript
require("notebook/js/notebook").Notebook.prototype.scroll_to_bottom = function () {}
2

In the similar way that you can hack a cell to autorun, you can add the following cell:

%%javascript
require(
        ["notebook/js/outputarea"],
        function (oa) {
            oa.OutputArea.auto_scroll_threshold = -1;
            console.log("Setting auto_scroll_threshold to -1");
        });

which will set the auto_scroll_threshold to -1 which means never autoscroll.

This works on my notebooks that are trusted (e.g. jupyter trust notebook.ipynb), not sure if any cells are executed in untrusted notebooks.

0

For version 7 or higher, go to Setting > Settings Editor > Jupyter Notebook Notebook and uncheck Auto Scroll Outputs.

Note, the menu item Settings Editor is not available in the notebook view, only in the file browser.

-1

It can be done via UI. In the latest version (notebook 7) right clicking on the work area brings up the menu: Screenshot of the menu

1
  • 1
    This will disable it at one time, but as soon as a new line of output is printed for the cell (e.g. if a loop is being executed), it will go back to scrolling! so frustrating.
    – sh37211
    Nov 7, 2023 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.