Quantcast

[IPython-User] Hide code cells in the notebook

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[IPython-User] Hide code cells in the notebook

Thomas Kluyver-2
I just came across this blog post - the author has a bit of Python, which produces a bit of HTML+Javascript, that can interactively hide/show the code parts of a notebook:

http://ganwellresource.blogspot.co.uk/2012/11/hide-ipython-notebook-input-boxes.html

Thomas

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Brian Granger-3
Yes, this is very nice.  But, this is a feature that cannot be
implemented in the notebook itself.  Please follow up privately with
me if you have questions about this.

On Sat, Nov 24, 2012 at 5:57 AM, Thomas Kluyver <[hidden email]> wrote:

> I just came across this blog post - the author has a bit of Python, which
> produces a bit of HTML+Javascript, that can interactively hide/show the code
> parts of a notebook:
>
> http://ganwellresource.blogspot.co.uk/2012/11/hide-ipython-notebook-input-boxes.html
>
> Thomas
>
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user
>



--
Brian E. Granger
Cal Poly State University, San Luis Obispo
[hidden email] and [hidden email]
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Thomas Kluyver-2

I wasn't particularly suggesting we implement it, just making people aware of it. That said, it seems counterintuitive that it couldn't be implemented in the notebook. Is there some technical limitation that i'm not aware of?

On Nov 25, 2012 10:00 PM, "Brian Granger" <[hidden email]> wrote:
Yes, this is very nice.  But, this is a feature that cannot be
implemented in the notebook itself.  Please follow up privately with
me if you have questions about this.

On Sat, Nov 24, 2012 at 5:57 AM, Thomas Kluyver <[hidden email]> wrote:
> I just came across this blog post - the author has a bit of Python, which
> produces a bit of HTML+Javascript, that can interactively hide/show the code
> parts of a notebook:
>
> http://ganwellresource.blogspot.co.uk/2012/11/hide-ipython-notebook-input-boxes.html
>
> Thomas
>
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user
>



--
Brian E. Granger
Cal Poly State University, San Luis Obispo
[hidden email] and [hidden email]
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Brian Granger-3
It is a legal, not technical issue that I don't want to discuss publicly.

On Sun, Nov 25, 2012 at 2:20 PM, Thomas Kluyver <[hidden email]> wrote:

> I wasn't particularly suggesting we implement it, just making people aware
> of it. That said, it seems counterintuitive that it couldn't be implemented
> in the notebook. Is there some technical limitation that i'm not aware of?
>
> On Nov 25, 2012 10:00 PM, "Brian Granger" <[hidden email]> wrote:
>>
>> Yes, this is very nice.  But, this is a feature that cannot be
>> implemented in the notebook itself.  Please follow up privately with
>> me if you have questions about this.
>>
>> On Sat, Nov 24, 2012 at 5:57 AM, Thomas Kluyver <[hidden email]> wrote:
>> > I just came across this blog post - the author has a bit of Python,
>> > which
>> > produces a bit of HTML+Javascript, that can interactively hide/show the
>> > code
>> > parts of a notebook:
>> >
>> >
>> > http://ganwellresource.blogspot.co.uk/2012/11/hide-ipython-notebook-input-boxes.html
>> >
>> > Thomas
>> >
>> > _______________________________________________
>> > IPython-User mailing list
>> > [hidden email]
>> > http://mail.scipy.org/mailman/listinfo/ipython-user
>> >
>>
>>
>>
>> --
>> Brian E. Granger
>> Cal Poly State University, San Luis Obispo
>> [hidden email] and [hidden email]
>> _______________________________________________
>> IPython-User mailing list
>> [hidden email]
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user
>



--
Brian E. Granger
Cal Poly State University, San Luis Obispo
[hidden email] and [hidden email]
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Mark Starnes
In reply to this post by Thomas Kluyver-2
On Sat, Nov 24, 2012 at 01:57:45PM +0000, Thomas Kluyver wrote:
> I just came across this blog post - the author has a bit of Python, which
> produces a bit of HTML+Javascript, that can interactively hide/show the code
> parts of a notebook:
>
> http://ganwellresource.blogspot.co.uk/2012/11/
> hide-ipython-notebook-input-boxes.html
>
> Thomas

> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user


First, a big thank-you to everyone who has
provided to IPython over the years.  I've been
using it since college and continue to use it at
work:  the notebook has changed the way I work.
I think it's wonderful.

The hiding of code cells was something I am
interested in so when I saw Thomas' comment,
I was overjoyed.  I followed it, installed the
code and started exploring Pandas.  I toggled
my input and saved the document before messing
around more.

The toggled output document, when saved, saved
*without* the original code (now hidden), without
out (plots, output etc) but with markdown text.
On reloading, all the original code and plots etc
were lost.

So, beware!  I can replicate this behaviour in
seconds with the following process:

In [1]: from pretty import *
        html_settings()
Out[1]: Toggle Input
In [2]: print 'Dont save with input toggled!'

Run all cells, check the screen output, hit `Toggle Input',
then save the document.  Exit, reload.

Now I find my archive isn't working either.  :(
This behaviour is probably obvious to most.  Not
me, unfortunately.

Take care!

Best regards,

Mark.
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Johan Beke
Putting the following code in a markdown cell works fine for me:

<script type="text/javascript">
    show=true;
    function toggle(){
        if (show){
            $('div.input').hide();
        }else{
            $('div.input').show();
        }
        show = !show
    }
</script>
<a href="javascript:toggle()" target="_self">toggle input</a>

Johan

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Raju Joseph
Thanks a lot Johan. This is going to be most helpful.

**NOOB question alert**
Is there any way in which a markdown cell could be used to create an input form to accept variables/parameters? 
These variable values could then be used to pipe into the code in the IPython input cells.

This along with "toggle input" would be very useful in building quick-fix applications or application prototypes. (especially custom reporting applications)
Such a notebook created could then be safely shared with business teams (aka teams who go glassy eyed on seeing code that need to be meddled with) 

I believe raw input is currently not handled by IPython, hence not sure if that would prevent the creation of such a form.

Seeking forgiveness in advance if the question was a stupid one.

Many Thanks,
Raju


On Tue, Nov 27, 2012 at 12:25 AM, Johan Beke <[hidden email]> wrote:
Putting the following code in a markdown cell works fine for me:

<script type="text/javascript">
    show=true;
    function toggle(){
        if (show){
            $('div.input').hide();
        }else{
            $('div.input').show();
        }
        show = !show
    }
</script>
<a href="javascript:toggle()" target="_self">toggle input</a>

Johan

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user




--
--raju

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Matthias Bussonnier

Le 27 nov. 2012 à 09:06, Raju Joseph a écrit :

> Thanks a lot Johan. This is going to be most helpful.
>
> **NOOB question alert**
> Is there any way in which a markdown cell could be used to create an input form to accept variables/parameters?
> These variable values could then be used to pipe into the code in the IPython input cells.

Yes it is,
Markdown support html and javascript <script> tag.

just write your form and bind `submit` (or anything  else) to a function that call
IPython.notebook.kernel.execute('stringofcode',callbackfunction);


>
> This along with "toggle input" would be very useful in building quick-fix applications or application prototypes. (especially custom reporting applications)
> Such a notebook created could then be safely shared with business teams (aka teams who go glassy eyed on seeing code that need to be meddled with)

Toggle input has already been discussed, we want to do it but
  * need to find the correct UI.
  * There was some issues with CodeMirror Library in hiding code cell.

> I believe raw input is currently not handled by IPython, hence not sure if that would prevent the creation of such a form.

Raw input prevent **python** from asking the user to type.
As long as you know that the user will have to enter something you could ask JS to pop up a dialog.
This just is not be possible **while** python code are executed.

> Seeking forgiveness in advance if the question was a stupid one.

That was not a stupid question, and questions are never stupid,
The answer is just  more obvious to people in the field.

--
Matthias

>
> Many Thanks,
> Raju
>
>
> On Tue, Nov 27, 2012 at 12:25 AM, Johan Beke <[hidden email]> wrote:
> Putting the following code in a markdown cell works fine for me:
>
> <script type="text/javascript">
>     show=true;
>     function toggle(){
>         if (show){
>             $('div.input').hide();
>         }else{
>             $('div.input').show();
>         }
>         show = !show
>     }
> </script>
> <a href="javascript:toggle()" target="_self">toggle input</a>
>
> Johan
>
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
> --
> --raju
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Raju Joseph
This is going to be neat. 
Thanks as always Matthias and for correcting my assumption on the "raw input" front....

Let me get my hands dirty on this.


On Tue, Nov 27, 2012 at 3:02 PM, Matthias BUSSONNIER <[hidden email]> wrote:

Le 27 nov. 2012 à 09:06, Raju Joseph a écrit :

> Thanks a lot Johan. This is going to be most helpful.
>
> **NOOB question alert**
> Is there any way in which a markdown cell could be used to create an input form to accept variables/parameters?
> These variable values could then be used to pipe into the code in the IPython input cells.

Yes it is,
Markdown support html and javascript <script> tag.

just write your form and bind `submit` (or anything  else) to a function that call
IPython.notebook.kernel.execute('stringofcode',callbackfunction);


>
> This along with "toggle input" would be very useful in building quick-fix applications or application prototypes. (especially custom reporting applications)
> Such a notebook created could then be safely shared with business teams (aka teams who go glassy eyed on seeing code that need to be meddled with)

Toggle input has already been discussed, we want to do it but
  * need to find the correct UI.
  * There was some issues with CodeMirror Library in hiding code cell.

> I believe raw input is currently not handled by IPython, hence not sure if that would prevent the creation of such a form.

Raw input prevent **python** from asking the user to type.
As long as you know that the user will have to enter something you could ask JS to pop up a dialog.
This just is not be possible **while** python code are executed.

> Seeking forgiveness in advance if the question was a stupid one.

That was not a stupid question, and questions are never stupid,
The answer is just  more obvious to people in the field.

--
Matthias
>
> Many Thanks,
> Raju
>
>
> On Tue, Nov 27, 2012 at 12:25 AM, Johan Beke <[hidden email]> wrote:
> Putting the following code in a markdown cell works fine for me:
>
> <script type="text/javascript">
>     show=true;
>     function toggle(){
>         if (show){
>             $('div.input').hide();
>         }else{
>             $('div.input').show();
>         }
>         show = !show
>     }
> </script>
> <a href="javascript:toggle()" target="_self">toggle input</a>
>
> Johan
>
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
> --
> --raju
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user



--
--raju

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Norfeldt
In reply to this post by Johan Beke
Doing some markup of your code and the solution from this post gave me a nice button:

<script type="text/javascript">
    on = "View input";
    off = "Hide input"
    function onoff(){
      currentvalue = document.getElementById('onoff').value;
      if(currentvalue == off){
        document.getElementById("onoff").value=on;
          $('div.input').hide();
      }else{
        document.getElementById("onoff").value=off;
          $('div.input').show();
      }
}
</script>
<input type="button" value="Hide input" id="onoff" onclick="onoff();">
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Norfeldt
Same same but different

<script type="text/javascript">
    on = "View input";
    off = "Hide input"
    function onoff(){
      currentvalue = document.getElementById('onoff').value;
      if(currentvalue == off){
        document.getElementById("onoff").value=on;
          $('div.input').hide();
      }else{
        document.getElementById("onoff").value=off;
          $('div.input').show();
      }
}
</script>
<input type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="Hide input" id="onoff" onclick="onoff();">

(this button has the same layout as the notebook theme)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Jean-Louis 'Hans' Fuchs
In reply to this post by Mark Starnes
Hi Everybody

I'd like to let you know, that Mark contacted me and I fixed the
problem of loosing code. I changed classes to remove gaps between
outputs and I didn't realize that the notebook uses these to save the
contents.

In the new version I don't touch any internals of the notebook.

Best,
        Jean-Louis



On 2012-11-26 17:23:35 +0000, Mark Starnes said:

> On Sat, Nov 24, 2012 at 01:57:45PM +0000, Thomas Kluyver wrote:
>> I just came across this blog post - the author has a bit of Python, which
>> produces a bit of HTML+Javascript, that can interactively hide/show the code
>> parts of a notebook:
>>
>> http://ganwellresource.blogspot.co.uk/2012/11/
>> hide-ipython-notebook-input-boxes.html
>>
>> Thomas
>
>> _______________________________________________
>> IPython-User mailing list
>> [hidden email]
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
> First, a big thank-you to everyone who has
> provided to IPython over the years.  I've been
> using it since college and continue to use it at
> work:  the notebook has changed the way I work.
> I think it's wonderful.
>
> The hiding of code cells was something I am
> interested in so when I saw Thomas' comment,
> I was overjoyed.  I followed it, installed the
> code and started exploring Pandas.  I toggled
> my input and saved the document before messing
> around more.
>
> The toggled output document, when saved, saved
> *without* the original code (now hidden), without
> out (plots, output etc) but with markdown text.
> On reloading, all the original code and plots etc
> were lost.
>
> So, beware!  I can replicate this behaviour in
> seconds with the following process:
>
> In [1]: from pretty import *
>         html_settings()
> Out[1]: Toggle Input
> In [2]: print 'Dont save with input toggled!'
>
> Run all cells, check the screen output, hit `Toggle Input',
> then save the document.  Exit, reload.
>
> Now I find my archive isn't working either.  :(
> This behaviour is probably obvious to most.  Not
> me, unfortunately.
>
> Take care!
>
> Best regards,
>
> Mark.


--
Adfinis SyGroup AG
Jean-Louis 'Hans' Fuchs, Software Engineer

Keltenstrasse 98 | CH-3018 Bern
Tel.: +41 31 550 31 11


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

Jean-Louis 'Hans' Fuchs
In reply to this post by Mark Starnes
Hi Everybody

I'd like to let you know, that Mark contacted me and I fixed the
problem of loosing code. I changed classes of divs to remove gaps between
outputs and I didn't realize that the notebook uses these classes to save the
contents.

In the new version I don't touch any internals of the notebook.

Best,
        Jean-Louis

On 2012-11-26 17:23:35 +0000, Mark Starnes said:

> On Sat, Nov 24, 2012 at 01:57:45PM +0000, Thomas Kluyver wrote:
>> I just came across this blog post - the author has a bit of Python, which
>> produces a bit of HTML+Javascript, that can interactively hide/show the code
>> parts of a notebook:
>>
>> http://ganwellresource.blogspot.co.uk/2012/11/
>> hide-ipython-notebook-input-boxes.html
>>
>> Thomas
>
>> _______________________________________________
>> IPython-User mailing list
>> [hidden email]
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
> First, a big thank-you to everyone who has
> provided to IPython over the years.  I've been
> using it since college and continue to use it at
> work:  the notebook has changed the way I work.
> I think it's wonderful.
>
> The hiding of code cells was something I am
> interested in so when I saw Thomas' comment,
> I was overjoyed.  I followed it, installed the
> code and started exploring Pandas.  I toggled
> my input and saved the document before messing
> around more.
>
> The toggled output document, when saved, saved
> *without* the original code (now hidden), without
> out (plots, output etc) but with markdown text.
> On reloading, all the original code and plots etc
> were lost.
>
> So, beware!  I can replicate this behaviour in
> seconds with the following process:
>
> In [1]: from pretty import *
>         html_settings()
> Out[1]: Toggle Input
> In [2]: print 'Dont save with input toggled!'
>
> Run all cells, check the screen output, hit `Toggle Input',
> then save the document.  Exit, reload.
>
> Now I find my archive isn't working either.  :(
> This behaviour is probably obvious to most.  Not
> me, unfortunately.
>
> Take care!
>
> Best regards,
>
> Mark.


--
Adfinis SyGroup AG
Jean-Louis 'Hans' Fuchs, Software Engineer

Keltenstrasse 98 | CH-3018 Bern
Tel.: +41 31 550 31 11


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hide code cells in the notebook

JGrif
This post has NOT been accepted by the mailing list yet.
In reply to this post by Norfeldt

I know this is an old post and people may have moved on.

But the markdown cell hide input button described in this thread is very useful.

However, I recently installed the latest ipython dev version, and now the button doesn't seem to be working any more.

Are there any obvious reasons for this?

Ta,

john
Loading...