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

Export to PDF still shows code #5

Closed
mgcdanny opened this issue Jan 25, 2016 · 37 comments
Closed

Export to PDF still shows code #5

mgcdanny opened this issue Jan 25, 2016 · 37 comments
Milestone

Comments

@mgcdanny
Copy link

Hi,

Thanks for the great plug-in. After I hide the code, the export to pdf still renders code cells. I am using "File" "Download As" "PDF" from the jupyter notebook browser.

Let me know if you have any suggestions. My goal is to render the notebook as a pdf without the code cells. Thanks!

@kirbs-
Copy link
Owner

kirbs- commented Jan 26, 2016

This plugin uses jQuery to show/hide the various sections. I'm guessing the the pdf exporter is reading directly from the notebook .ipynb file instead of rendering, then exporting. I haven't tried this, but exporting as slides or a html page then saving to pdf may work.

I'll take a look at this. I'm not that familar with the pdf exporter.

@kirbs-
Copy link
Owner

kirbs- commented Feb 3, 2016

Looks like the various exporters render directly from the .ipynb file. When I get some time I'll tinker with a custom exporter that respects the code hiding options selected.

@kirbs- kirbs- modified the milestones: 0.2.0, 1.5 Feb 3, 2016
@mgcdanny
Copy link
Author

mgcdanny commented Feb 3, 2016

Cool. Thanks !

@cenveoanalyst
Copy link

To hide the code for exporting would be greatly appreciated. Any update on this?

@kirbs-
Copy link
Owner

kirbs- commented Apr 11, 2016

@mgcdanny @cenveoanalyst I've added support for exporting on the dev branch. Travis CI is builds are failing on Python 3.x so you may see some problems. Python 2.7 works though.

@vinhdizzo
Copy link

@kirbs- looking forward to this enhancement. Just to confirm, when this becomes available, whenever we export the notebook to a different format via jupyter-nbconvert, whatever code or output we hide will be respected in the output file (eg, html), correct?

I'm using Jupyter with the R kernel. This should also work there, right? Thanks.

@kirbs-
Copy link
Owner

kirbs- commented Apr 18, 2016

@vinhdizzo this enhancement adds export options to nbconvert and to Jupyter notebook's UI. I believe it will work with any kernal. Look at the dev branch for more info.

@vinhdizzo
Copy link

@kirbs great, I look forward to when this get's rolled into master. Will test out then. Thanks again.

@kirbs- kirbs- mentioned this issue Apr 25, 2016
@kirbs- kirbs- closed this as completed Apr 25, 2016
@vinhdizzo
Copy link

Thanks @kirbs- , I just upgraded to 0.2.0 and upgraded nbcovert to 4.2 to test out the new rolled out feature. My tests:

  • The two html and pdf export buttons within the notebook did not work for me (no response)
  • nbconvert --to hide_code_html did work for me. My converted html file did indeed hide the raw input code. However, I still see the In [ ]: labels next to empty space. Is this intended? Any way to also hide this?

Thanks!

@kirbs-
Copy link
Owner

kirbs- commented Apr 25, 2016

Can you post the results from the installation process? The first issue sounds like the JS dependencies didn't get installed correctly. On the second issue, did you have the "Hide prompts" option selected?

@kirbs- kirbs- reopened this Apr 25, 2016
@vinhdizzo
Copy link

Second issue: ahh, Hide Prompt did fix it. For some reason I originally thought that referred to Hide Output.

hide_code upgrade:

$ pip install --upgrade hide_code
Collecting hide-code
  Downloading hide_code-0.2.0.tar.gz
Requirement already up-to-date: jupyter in c:\programfiles\continuum\anaconda3\lib\site-packages (from hide-code)
Collecting pdfkit (from hide-code)
  Downloading pdfkit-0.5.0.zip
Building wheels for collected packages: hide-code, pdfkit
  Running setup.py bdist_wheel for hide-code: started
  Running setup.py bdist_wheel for hide-code: finished with status 'error'
  Complete output from command C:\ProgramFiles\Continuum\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\v116795\\AppData\\Local\\Temp\\pip-build-or_oa8cp\\hide-code\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d C:\Users\v116795\AppData\Local\Temp\tmpvnfmvz8vpip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib
  creating build\lib\hide_code
  copying hide_code\hide_code.py -> build\lib\hide_code
  copying hide_code\hide_code_html_exporter.py -> build\lib\hide_code
  copying hide_code\hide_code_pdf_exporter.py -> build\lib\hide_code
  copying hide_code\hide_code_preprocessor.py -> build\lib\hide_code
  copying hide_code\__init__.py -> build\lib\hide_code
  copying hide_code\hide_code.js -> build\lib\hide_code
  copying hide_code\auto-load-server-extension.txt -> build\lib\hide_code
  copying hide_code\auto-load.txt -> build\lib\hide_code
  copying hide_code\LICENSE.txt -> build\lib\hide_code
  creating build\lib\hide_code\Templates
  copying hide_code\Templates\hide_code.tpl -> build\lib\hide_code\Templates
  copying hide_code\Templates\hide_code_article.tplx -> build\lib\hide_code\Templates
  copying hide_code\Templates\hide_code_base_style.tplx -> build\lib\hide_code\Templates
  installing to build\bdist.win-amd64\wheel
  running install
  running install_lib
  creating build\bdist.win-amd64
  creating build\bdist.win-amd64\wheel
  creating build\bdist.win-amd64\wheel\hide_code
  copying build\lib\hide_code\auto-load-server-extension.txt -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  copying build\lib\hide_code\auto-load.txt -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  copying build\lib\hide_code\hide_code.js -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  copying build\lib\hide_code\hide_code.py -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  copying build\lib\hide_code\hide_code_html_exporter.py -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  copying build\lib\hide_code\hide_code_pdf_exporter.py -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  copying build\lib\hide_code\hide_code_preprocessor.py -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  copying build\lib\hide_code\LICENSE.txt -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  creating build\bdist.win-amd64\wheel\hide_code\Templates
  copying build\lib\hide_code\Templates\hide_code.tpl -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code\Templates
  copying build\lib\hide_code\Templates\hide_code_article.tplx -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code\Templates
  copying build\lib\hide_code\Templates\hide_code_base_style.tplx -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code\Templates
  copying build\lib\hide_code\__init__.py -> build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code
  running install_egg_info
  running egg_info
  writing top-level names to hide_code.egg-info\top_level.txt
  writing requirements to hide_code.egg-info\requires.txt
  writing entry points to hide_code.egg-info\entry_points.txt
  writing dependency_links to hide_code.egg-info\dependency_links.txt
  writing hide_code.egg-info\PKG-INFO
  warning: manifest_maker: standard file '-c' not found

  reading manifest file 'hide_code.egg-info\SOURCES.txt'
  writing manifest file 'hide_code.egg-info\SOURCES.txt'
  Copying hide_code.egg-info to build\bdist.win-amd64\wheel\hide_code-0.2.0.data\..\hide_code-0.2.0-py3.5.egg-info
  running install_scripts
  Running post install task...
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\v116795\AppData\Local\Temp\pip-build-or_oa8cp\hide-code\setup.py", line 118, in <module>
      'hide_code_pdf = hide_code:HideCodePDFExporter',
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\distutils\dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\site-packages\wheel\bdist_wheel.py", line 212, in run
      self.run_command('install')
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "C:\Users\v116795\AppData\Local\Temp\pip-build-or_oa8cp\hide-code\setup.py", line 29, in run
      self.execute(_post_install, (self.install_lib, ), msg="Running post install task...")
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\distutils\cmd.py", line 336, in execute
      util.execute(func, args, msg, dry_run=self.dry_run)
    File "C:\ProgramFiles\Continuum\Anaconda3\lib\distutils\util.py", line 301, in execute
      func(*args)
    File "C:\Users\v116795\AppData\Local\Temp\pip-build-or_oa8cp\hide-code\setup.py", line 13, in _post_install
      from hide_code import hide_code
    File "c:\users\v116795\appdata\local\temp\pip-build-or_oa8cp\hide-code\hide_code\hide_code.py", line 10, in <module>
      import pdfkit
  ImportError: No module named 'pdfkit'

  ----------------------------------------
  Failed building wheel for hide-code
  Running setup.py clean for hide-code
  Running setup.py bdist_wheel for pdfkit: started
  Running setup.py bdist_wheel for pdfkit: finished with status 'done'
  Stored in directory: C:\Users\v116795\AppData\Local\pip\Cache\wheels\8e\fe\d0\ef49740186cbeece01d2bdc87a7a6903f0dfd6c256b5421446
Successfully built pdfkit
Failed to build hide-code
Installing collected packages: pdfkit, hide-code
  Found existing installation: hide-code 0.1.6
    Uninstalling hide-code-0.1.6:
      Successfully uninstalled hide-code-0.1.6
  Running setup.py install for hide-code: started
    Running setup.py install for hide-code: finished with status 'done'
Successfully installed hide-code-0.2.0 pdfkit-0.5.0
You are using pip version 8.0.2, however version 8.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

@vinhdizzo
Copy link

BTW, I just tried the export button again, and I get

404 : Not Found
You are requesting a page that does not exist!

@kirbs-
Copy link
Owner

kirbs- commented Apr 25, 2016

Try running from python.

import hide_code.hide_code as hc
hc.install()

Then restart jupyter.

@vinhdizzo
Copy link

Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import hide_code.hide_code as hc
hc.install()
>>> Starting hide_code.js install...
No config directories contain "custom" folder. Trying site-packages...
Copying hide_code.js to C:\ProgramFiles\Continuum\Anaconda3\lib\site-packages\notebook/static/custom
Attempting to configure custom.js to auto-load hide__code.js...
Custom.js already configured to auto-load hide_code.js.
Attempting to configure default profile to auto-load hide_code export handlers.
jupyter_notebook_config already configured to auto-load export handlers.
>>>

@kirbs-
Copy link
Owner

kirbs- commented Apr 25, 2016

Do you see hide_code.js in C:\ProgramFiles\Continuum\Anaconda3\lib\site-packages\notebook\static\custom ?

@vinhdizzo
Copy link

Yes, I see custom.css, custom.js, and hide_code.js.

@kirbs-
Copy link
Owner

kirbs- commented Apr 25, 2016

Does pip show hide_code as version 0.2.0?

@vinhdizzo
Copy link

It did when I installed it. Here it is when I just checked:

$ pip freeze | grep hide
hide-code==0.2.0

Note that when I use jupyter-nbconvert --to hide_code_html, things work. It's just that button that doesn't work. Thanks.

@kirbs-
Copy link
Owner

kirbs- commented Apr 25, 2016

Odd, are you getting any JS errors when you click on either export button?

@vinhdizzo
Copy link

No. In the jupyter console, all I see is:

404 GET /notebooks/path/to/Untitled.ipynb/export/html

@kirbs-
Copy link
Owner

kirbs- commented Apr 25, 2016

The installation didn't run smoothly, so I'm guessing the export handlers for Jupyter notebook didn't load correctly. Run the code below from any notebook.

from notebook.services.config import ConfigManager
import jupyter_core.paths as j_path
server_cm = ConfigManager(config_dir=j_path.jupyter_config_dir())
print(server_cm.get('jupyter_notebook_config'))

You should see this if the export handlers are enabled.
{u'NotebookApp': {u'server_extensions': [u'hide_code.hide_code']}}
Also, just to confirm, did you restart Jupyter after upgrading hide code?

@vinhdizzo
Copy link

Yes, I did restart Jupyter after upgrading hide_code. I just did it again. Within a notebook cell, I get:

Error in parse(text = x, srcfile = src): <text>:1:6: unexpected symbol
1: from notebook.services.config

When I open a python interpreter and run your code, I do get

{'NotebookApp': {'server_extensions': ['hide_code.hide_code']}}

@kirbs-
Copy link
Owner

kirbs- commented Apr 25, 2016

Definitely sounds like the export handlers didn't load. Try starting jupyter using
jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"

@vinhdizzo
Copy link

Same problem persists. Here's the console log:

$ jupyter-notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
[W 14:55:35.842 NotebookApp] Unrecognized JSON config file version, assuming version 1
[I 14:55:36.418 NotebookApp] Serving notebooks from local directory: C:\Users\my_id
[I 14:55:36.418 NotebookApp] 0 active kernels
[I 14:55:36.418 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
[I 14:55:36.418 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 14:55:52.015 NotebookApp] Kernel started: b7bd56ed-97c5-4cb8-a587-ed090dbcbc8d
[1] "Got unhandled msg_type:" "comm_open"
[W 14:56:04.750 NotebookApp] 404 GET /notebooks/Projects/Untitled.ipynb/export/html (::1): No such file or directory: Projects/Untitled.ipynb/export/html
[W 14:56:04.758 NotebookApp] 404 GET /notebooks/Projects/Untitled.ipynb/export/html (::1) 8.00ms referer=http://localhost:8888/notebooks/Projects/Untitled.ipynb

@kirbs-
Copy link
Owner

kirbs- commented Apr 26, 2016

I just pushed v0.2.1. I added some logging to the release to help troubleshoot. Would you upgrade, restart Jupyter, try exporting and paste the console results. Also run the code below:

import hide_code as hc
print hc.setup_info()

@vinhdizzo
Copy link

Here's the upgrade:

$ pip install --upgrade hide_code
Collecting hide-code
  Downloading hide_code-0.2.1.tar.gz
Requirement already up-to-date: jupyter in c:\programfiles\continuum\anaconda3\lib\site-packages (from hide-code)
Requirement already up-to-date: pdfkit in c:\programfiles\continuum\anaconda3\lib\site-packages (from hide-code)
Building wheels for collected packages: hide-code
  Running setup.py bdist_wheel for hide-code: started
  Running setup.py bdist_wheel for hide-code: finished with status 'done'
  Stored in directory: C:\Users\v116795\AppData\Local\pip\Cache\wheels\5d\db\b0\5d1003c4d3b7345c4bc650c720c9cd2421c9fb4d7d6ea63860
Successfully built hide-code
Installing collected packages: hide-code
  Found existing installation: hide-code 0.2.0
    Uninstalling hide-code-0.2.0:
      Successfully uninstalled hide-code-0.2.0
Successfully installed hide-code-0.2.1

I just realized something I forgot to mention (stupid me, apologies). I've been using the R kernel, and hence those python debug messages did not run before. Here it is with the Python3 kernel:

from notebook.services.config import ConfigManager
import jupyter_core.paths as j_path
server_cm = ConfigManager(config_dir=j_path.jupyter_config_dir())
print(server_cm.get('jupyter_notebook_config'))
{'NotebookApp': {'server_extensions': ['hide_code.hide_code']}}

import hide_code as hc
print(hc.setup_info())
Installation dir: C:\ProgramFiles\Continuum\Anaconda3\lib\site-packages
Configuration dir:C:\Users\My\Home\Path\.jupyter
Export handler extensions: Loaded
Hide Code files: ['auto-load-server-extension.txt', 'auto-load.txt', 'hide_code.js', 'hide_code.py', 'hide_code_html_exporter.py', 'hide_code_pdf_exporter.py', 'hide_code_preprocessor.py', 'LICENSE.txt', '__init__.py']
Custom JS contents: 
 define([
 'base/js/events'
 ], 
 function(events) {
     events.on('app_initialized.NotebookApp', function(){
         require(['custom/hide_code']);
     });
 }); 

When I click the export button, I get a popup that says I couldn't find a kernel matching python3/export/html/export/html. Please select a kernel: [Choose Python 3 or R]

So, maybe it's not working because hide_code only works with the python2 kernel?

@kirbs-
Copy link
Owner

kirbs- commented Apr 26, 2016

Thanks, hide_code installed cleanly for you. I tested exporting with R kernel. The routes used by the R kernel aren't defined. This is a bug in hide_code's routing. I'll get this updated. If you delete ?kernel_name=ir from the url, then click an export button it works.

@vinhdizzo
Copy link

I don't see ?kernel_name=ir in my notebook's url. Maybe this is a python3 thing?

Also, based on my previous results, it appears that hide_code does not work with python3 kernel?

@kirbs-
Copy link
Owner

kirbs- commented Apr 26, 2016

I've fixed the routing bug on the dev branch. Would you download, unzip, and run python setup.py install from the directory?

It should work with all kernels. I've tested with python 2.7, 3.5 and now R; everything works as expected.

@vinhdizzo
Copy link

Hmm, still not working on the R kernel or python3 kernel (404 file not found). Here's my install log:

$ /cygdrive/c/ProgramFiles/Continuum/Anaconda3/python setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
running egg_info
writing dependency_links to hide_code.egg-info\dependency_links.txt
writing requirements to hide_code.egg-info\requires.txt
writing hide_code.egg-info\PKG-INFO
writing top-level names to hide_code.egg-info\top_level.txt
writing entry points to hide_code.egg-info\entry_points.txt
reading manifest file 'hide_code.egg-info\SOURCES.txt'
writing manifest file 'hide_code.egg-info\SOURCES.txt'
removing 'C:\ProgramFiles\Continuum\Anaconda3\Lib\site-packages\hide_code-0.2.2-py3.5.egg-info' (and everything under it)
Copying hide_code.egg-info to C:\ProgramFiles\Continuum\Anaconda3\Lib\site-packages\hide_code-0.2.2-py3.5.egg-info
running install_scripts
Running post install task...
Starting hide_code.js install...
No config directories contain "custom" folder. Trying site-packages...
Copying hide_code.js to C:\ProgramFiles\Continuum\Anaconda3\lib\site-packages\notebook\static\custom
Attempting to configure custom.js to auto-load hide__code.js...
Custom.js already configured to auto-load hide_code.js.
Attempting to configure auto-loading for hide_code export handlers.
Jupyter already configured to auto-load export handlers.

In the Jupyter console, in addition to the 404 GET error, I see:

[1] "Got unhandled msg_type:" "comm_open"

@kirbs-
Copy link
Owner

kirbs- commented Apr 26, 2016

I noticed in here

[W 14:56:04.750 NotebookApp] 404 GET /notebooks/Projects/Untitled.ipynb/export/html (::1): No such file or directory: Projects/Untitled.ipynb/export/html

you're testing with a notebook nested in the root directory. I found another routing issue with this use case. I've pushed a fix to the dev branch. Would you download, unzip, install and retest?

@vinhdizzo
Copy link

Still doesn't work for me. In Jupyter console:

No such file or directory: Folder1/Projects/Untitled.ipynb/export/html

@kirbs-
Copy link
Owner

kirbs- commented Apr 26, 2016

What the full URL you see with a notebook open? I only implemented support for one child folder level. For example: juypter_root/some_folder/some_notebook.ipynb should work, but juypter_root/some_folder/another_folder/some_notebook.ipynb will not.

@vinhdizzo
Copy link

URL: http://localhost:8888/notebooks/Folder1/Projects/Untitled1.ipynb/export/html
Based on what you stated, this is not supported?

I copied the file into Folder1, and yes, the export button works.

@kirbs-
Copy link
Owner

kirbs- commented Apr 26, 2016

Glad that finally worked. The plugin should support any number of nested folders. I hard coded it to two levels deep to troubleshoot your issue. I'll get this fixed for the next release.

@kirbs-
Copy link
Owner

kirbs- commented May 1, 2016

This is resolved in 0.3.0.

@kirbs- kirbs- closed this as completed May 1, 2016
@vinhdizzo
Copy link

Thanks, confirming both the 'export to html' and 'export to pdf via 'wkhtmltopdf' works for me.

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

4 participants