Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide input cells #534

Open
ellisonbg opened this issue Oct 6, 2015 · 74 comments
Open

Hide input cells #534

ellisonbg opened this issue Oct 6, 2015 · 74 comments

Comments

@ellisonbg
Copy link
Contributor

I plan on implementing the hiding of input cells. Might not happen for 4.1, but I will be optimistic for now.

@ellisonbg ellisonbg added this to the 4.1 milestone Oct 6, 2015
@dsblank
Copy link
Member

dsblank commented Oct 6, 2015

Woot!

BTW, I like our variation of making a Tabbed Input/Output cell [1] such that you can see the code in the Input tab, but defaults to showing the Output tab initially. Also can display the input next to output.

[1] - https://www.youtube.com/watch?t=19&v=WwoTzvOkEJQ

@ellisonbg
Copy link
Contributor Author

I can imagine that this view would be useful sometimes. But initially this
will be as simple as possible - possibly without UI (just in the command
palette).

On Tue, Oct 6, 2015 at 4:02 PM, Doug Blank notifications@github.com wrote:

Woot!

BTW, I like our variation of making a Tabbed Input/Output cell [1] such
that you can see the code in the Input tab, but defaults to showing the
Output tab initially. Also can display the input next to output.

[1] - https://www.youtube.com/watch?t=19&v=WwoTzvOkEJQ


Reply to this email directly or view it on GitHub
#534 (comment).

Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgranger@calpoly.edu and ellisonbg@gmail.com

@akhmerov
Copy link
Member

akhmerov commented Oct 8, 2015

Would it be possible to expose the JS so that it survives nbconvert? Otherwise any derived materials would need to re-implement show/hide machinery.

I'm also 👍 on the possibility of switching input on one cell only, imagine publishing lecture materials in a non-programming course, where you only might want to check how a particular thing is produced.

@Carreau Carreau modified the milestones: 4.x, 4.1 Oct 15, 2015
@ellisonbg ellisonbg modified the milestones: 4.x, 4.2 Oct 28, 2015
@Saynah
Copy link

Saynah commented Dec 1, 2015

Here's a snipped that works for me if I run as HTML in the 1st cell.

<script>
    var code_show=true; //true -> hide code at first

    function code_toggle() {
        $('div.prompt').hide(); // always hide prompt

        if (code_show){
            $('div.input').hide();
        } else {
            $('div.input').show();
        }
        code_show = !code_show
    }
    $( document ).ready(code_toggle);
</script>

Here's the button.

<a href="javascript:code_toggle()">[Toggle Code]</a>

@ecollins
Copy link

I just signed in to thank @Saynah for that great hack. I don't use Jupyter specifically because it doesn't have cell folding, but this is the closest I've found so far.

@kirbs-
Copy link

kirbs- commented Jan 26, 2016

@Saynah, @ecollins, I created a code hiding plugin for Jupyter a couple of months ago. If you're interested in check out hide_code.

Edit: fixed a typo.

@ruffsl
Copy link

ruffsl commented Jan 26, 2016

Thanks @kirbs- , had some issue the first time around the install. It'd definitely be nice to see this feature upstream.

@iondiode
Copy link

It seems like this would be nice done a cell magic, then it's easy to selectively hide cells, not sure though. still learning the system. Plus I seem to be running an ancient version

@takluyver
Copy link
Member

I don't think a cell magic is the right thing for this:

  • Hiding cells should work the same way for any kernel, and magics are not general.
  • Cell magics usually affect what the kernel does with code, whereas here we don't want that to change

If you're on an old version, have a look at the upgrade instructions here:
http://jupyter.readthedocs.org/en/latest/install.html#upgrading

@cenveoanalyst
Copy link

Hiding input cells for HTML output would be greatly appreciated!

@caos21
Copy link

caos21 commented Mar 1, 2016

I second that!

@cenveoanalyst
Copy link

I have cell hiding on HTML export figured out with a helpful piece of code to trigger upon export; but now that I'm moving to deploying Jupyterhub in my organization I really would appreciate the ability to hide live input cells so users don't see them when they run their notebooks.

@amueller
Copy link

The hide_code notebook extension is nice, but it doesn't hide the code when exporting. Can an nbextension register preprocessors? As hide_code adds a variable to the meta-data, that should be trivial to implement.

@juhasch
Copy link
Contributor

juhasch commented Mar 19, 2016

You can hide the code in nbconvert using a custom template.
Like this template hide_input_output.tpl for conversion to HTML. You have to change the metadata variable name in the template, because it was made for another notebook extension.

For conversion to TeX or PDF you can take a look at this template printviewlatex.tplx and modify it accordingly.

@amueller
Copy link

I think it would be cleaner to do this with a preprocessor (which I just did locally). I fell the hiding of cells should be independent of the template.

@BreitA
Copy link

BreitA commented Apr 5, 2016

It would be neat if in addition to the feature we could allow to export to pdf/html removing/hiding input cell code and prompt so we could have a clean pdf/html output without any code but with the beautiful graphs, markdown and results.
A man can dream.

@amueller
Copy link

amueller commented Apr 5, 2016

@BreitA that's super easy. The hard part is getting rid of the prompt for the output. Lemme send a PR.

@amueller
Copy link

amueller commented Apr 5, 2016

Hm actually I realized that I was doing the wrong thing and also removed the output of the cell. That was simple.

@Carreau
Copy link
Member

Carreau commented Apr 5, 2016

Oops, ping @JamiesHQ

@ellisonbg
Copy link
Contributor Author

I don't now the current state of how lab and the notebook are handling this metadata, we would have to do some tests.

@jrbrodie77
Copy link

I've been trying to get PDF export to hide input cells and have done this successfully with tplx templates etc.

My problem now is that hide_input seems to hide the cells even if I disable all extensions? Is hide_input actually being used by vanilla notebook? or do I have an extension mysteriously running somewhere?

@takluyver
Copy link
Member

I don't think the notebook web interface uses any metadata for hiding input yet, though maybe it's gone in without me noticing.

Stuff to check: browser Javascript console, logging from the server, run jupyter nbextension list

@gnestor gnestor modified the milestones: 5.3, 5.4 Jan 5, 2018
@takluyver takluyver modified the milestones: 5.4, 5.5 Jan 27, 2018
@SimonEnsemble
Copy link

+10, would be perfect if we can edit the meta-data in Jupyter Lab to:

  • hide input of cell and only show output
  • hide cell numbers, looks tacky.

See Ref. here.

@ellisonbg
Copy link
Contributor Author

It is my understanding that what @takluyver says is correct (not using the metadata in notebook yet). We do have work in progress to add that handling to lab though.

@MSeal
Copy link

MSeal commented Nov 7, 2018

I realize this has been open for a while and there were some difficulties here, but I have been getting a lot of questions regarding why classic jupyter doesn't respect the jupyter metadata source_hidden. JupyterLab, nbconvert, nbformat, and nteract all respect the field (if I recall correctly).

I see there's a lot of discussion on the DOM structure and how JupyterLab reimplemented that, but it seems like source_hidden and outputs_hidden wouldn't need drastic changes to enforce (even if classic couldn't edit the attribute easily). My front-end dev skills are a bit rusty but would adding a metadata check to

var input_area = $('<div/>').addClass('input_area');
to set display: None be 80% of the work for source_hidden? Seems like it'd only need to capture initial render and metadata edit events to adjust the display attribute.

Thoughts/comments?

@Zsailer
Copy link
Member

Zsailer commented Feb 3, 2022

Thanks @ellisonbg! This is a great idea!

This is currently possible in JupyterLab and will be possible in the coming Notebook v7 (which inherits from JupyterLab's notebook package). Look out for this feature in our next major release!

We'll leave this issue open until v7 is published.

@andrii-i
Copy link
Contributor

Notebook 7 is close to be published. JupyterLab adds ability to collapse an input cell so that only 1st line of the cell is visible. But this does not hide the input cell completely which is the desired feature here. Moving this issue to 7.0.x for further discussion and follow up, please let me know if I'm missing something (CC @Zsailer).

collapse_input

@andrii-i andrii-i modified the milestones: 7.0, 7.0.x Jun 13, 2023
@rgbkrk
Copy link
Member

rgbkrk commented Aug 12, 2023

Love it. That's a great start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests