Hide the input cells from your IPython slides

  |   Source   |   Minimap   |   Note: Just click on any IPython input cell to see the output.

A tweet arrived...

And my answer was YES...

How we can easily do it? Just follow these few steps:

Rational: We are going to use the power of IPython.nbconvert library to use a modified jinja template which will let us hide theinput cells in our IPython slides. To achieve this goal, we are going to use the same approach described in a previous post. Hence, our input cells will be hidden by default, but they will show up if we click on the corresponding output cell area.

OK, I first wrote a custom template and named it as output_toggle.tpl:

In [1]:
!cat /media/datos/Ejemplos/output_toggle.tpl
  Click me!
{%- extends 'slides_reveal.tpl' -%}

{% block input_group -%}
<div class="input_hidden">
{{ super() }}
</div>
{% endblock input_group %}

{%- block header -%}
{{ super() }}

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<style type="text/css">
//div.output_wrapper {
//  margin-top: 0px;
//}
.input_hidden {
  display: none;
//  margin-top: 5px;
}
</style>

<script>
$(document).ready(function(){
  $(".output_wrapper").click(function(){
      $(this).prev('.input_hidden').slideToggle();
  });
})
</script>
{%- endblock header -%}


The code is simple, but for a detailed explanation see my previous post.

Briefly, I just changed obvious things such as the encompassing of the input_group and the calling of .prev() method (instead of .next() one) inside the little javascript snippet.

Now, the second and last step was:

ipython nbconvert your_slides.ipynb --to slides --template output_toggle --post serve

and I got something like this (navigate and try it!):

OK, as you have seen in the example, your IPython slides will be delivered showing just the output cells... but if you need to show some input cells, just click on the corresponding output cell and you will get them. Nice, uh!

Hope it helps Thomas (and all the other people using the IPython slides)!

Damián.

Do you like the content? Great! Then help me to achieve a "Sustainable Crowdfunding"!

Comments powered by Disqus
Contents © 2014 Damian Avila - Powered by Nikola - Zen theme based in Arusahni's website-template
Creative Commons License BY-NC-SA