user3426752
user3426752

Reputation: 425

add hide_code to jupyter notebook

I am trying to add the hide_code option to my ipython notebook (jupyter, version 4, python 2.7). It is supposed to add a button or an option to the cell pull-down menu that allows me to hide the code in my ipython notebooks. I have successfully run the 'pip install hide_code' command from the terminal (MacOS X El Capitan). I have restarted the notebook and expected to see a new I have tried to restart the notebook program but nothing happens. I am not computer savvy enough to know what to do from here. Did I miss something?

Here is the github repository for the code:

https://pypi.python.org/pypi/hide_code/0.3.0

Upvotes: 1

Views: 3123

Answers (2)

Denisevi4
Denisevi4

Reputation: 81

OK I found a way to do it.

  1. Install hide_code... It will not work, though.
  2. Try to install it with (with dir="~/.ipython" or whatever)
import hide_code.hide_code as hc;
dir = "<full path to Jupyter config directory>";
hc.install(dir)

It will still not work, but it will copy a javascript file (hide_code.js) into that directory. We will use it in a bit.

  1. Let's find where those nbextensions are. Find one of them. For example, keyboard_shortcut_editor:
cd ~
find -name keyboard_shortcut_editor

Mine finds it ./.local/share/jupyter/nbextensions/keyboard_shortcut_editor Yours should be there too.

  1. Go to that directory
cd ./.local/share/jupyter/nbextensions/
ls

You see full list of various extensions. Let's copy one of them into hide_copy:

cp -r hide_input hide_code
cd hide_code
ls
  1. The important file there is main.js. Replace it with that hide_code.js from ~./ipython
cp ~./ipython/hide_code.js ./main.js
  1. Rename hide-input.yaml with hide-code.yaml and edit the content accordingly. Mainly, replace all Hide_Input references to Hide_Code. You can edit readme.md as well, but that doesn't matter. Because, the main thing, you created a new extension.

Now, if you launch your jupyter and go to http://localhost:8888/nbextensions, you will see Hide Code. And if click on that checkbox, it's on. Here are snapshots:

enter image description here

enter image description here

It is a weird sequence. But it worked for me. And the main thing, it puts it right where it needs to be. Hide_code actually needs to be a part of Nbextensions. I don't know why it is not. That way it's easy to turn it on and off any way you like it.

Upvotes: 1

PseudoAj
PseudoAj

Reputation: 5931

As described in the documentation: https://github.com/kirbs-/hide_code, you can troubleshoot by running the following code with appropriate Jupyter config directory location:

import hide_code.hide_code as hc
dir = "<full path to Jupyter config directory>"
hc.install(dir)

Upvotes: 0

Related Questions