-
Notifications
You must be signed in to change notification settings - Fork 44
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
Comments
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. |
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. |
Cool. Thanks ! |
To hide the code for exporting would be greatly appreciated. Any update on this? |
@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. |
@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. |
@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. |
@kirbs great, I look forward to when this get's rolled into master. Will test out then. Thanks again. |
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:
Thanks! |
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? |
Second issue: ahh,
$ 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. |
BTW, I just tried the export button again, and I get
|
Try running from python. import hide_code.hide_code as hc
hc.install() Then restart jupyter. |
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.
>>> |
Do you see hide_code.js in C:\ProgramFiles\Continuum\Anaconda3\lib\site-packages\notebook\static\custom ? |
Yes, I see |
Does pip show hide_code as version 0.2.0? |
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 |
Odd, are you getting any JS errors when you click on either export button? |
No. In the jupyter console, all I see is:
|
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. |
Yes, I did restart Jupyter after upgrading hide_code. I just did it again. Within a notebook cell, I get:
When I open a python interpreter and run your code, I do get
|
Definitely sounds like the export handlers didn't load. Try starting jupyter using |
Same problem persists. Here's the console log:
|
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() |
Here's the upgrade:
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:
When I click the export button, I get a popup that says So, maybe it's not working because |
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 |
I don't see Also, based on my previous results, it appears that |
I've fixed the routing bug on the dev branch. Would you download, unzip, and run It should work with all kernels. I've tested with python 2.7, 3.5 and now R; everything works as expected. |
Hmm, still not working on the R kernel or python3 kernel (404 file not found). Here's my install log:
In the Jupyter console, in addition to the
|
I noticed in here
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? |
Still doesn't work for me. In Jupyter console:
|
What the full URL you see with a notebook open? I only implemented support for one child folder level. For example: |
URL: I copied the file into Folder1, and yes, the export button works. |
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. |
This is resolved in 0.3.0. |
Thanks, confirming both the 'export to html' and 'export to pdf via 'wkhtmltopdf' works for me. |
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!
The text was updated successfully, but these errors were encountered: