Jupyter Notebook: command for hide the output of a cell?

前端 未结 7 703
被撕碎了的回忆
被撕碎了的回忆 2021-02-03 17:30

In my notebook, I have a cell returning temp calculation results. It\'s a bit long, so after it is run, I want to hide it and when needed, to show it.

To do it manually,

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-03 17:55

    Based on this, I just came up with this for myself a few minutes ago:

    %%javascript
    
    $('#maintoolbar-container').children('#toggleButton').remove()
    
    var toggle_button = ("");
    $('#maintoolbar-container').append(toggle_button);
    
    var code_shown = false;
    
    function code_toggle()
    {
    
        if (code_shown)
        {
            console.log("code shown")
            $('div.input').hide('500');
            $('#toggleButton').text('Show Code');
        }
        else
        {
            console.log("code not shown")
            $('div.input').show('500');
            $('#toggleButton').text('Hide Code');
        }
    
        code_shown = !code_shown;
    }
    
    $(document).ready(function()
    {
        code_shown=false;
        $('div.input').hide();
    });
    
    $('#toggleButton').on('click', code_toggle);
    

    It does have a glitch: each time you run that cell (which I put at the top), it adds a button. So, that is something that needs to be fixed. Would need to check in the maintoolbar-container to see if the button already exists, and then not add it.

    EDIT

    I added the necessary piece of code:

    $('#maintoolbar-container').children('#toggleButton').remove()
    

提交回复
热议问题