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
Nbconvert HTTP service #4656
Nbconvert HTTP service #4656
Conversation
<!-- <li id="download_py"><a href="#">Python (.py)</a></li> --> | ||
<li id="download_py"><a href="#">Python (.py)</a></li> | ||
<li id="download_html"><a href="#">HTML (.html)</a></li> | ||
<li id="download_rst"><a href="#">reST (.rst)</a></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I would make it a submenu.
- It would be nice to have it dynamic based on a list somewhere on server side.
- 1 and 2 could be done in subsequent PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid me it is already a submenu, would change it's nate to Save and download as...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submenu name: the model we're pushing (according to @minrk) is that the file on disk is always up to date, and user interaction is only for checkpoints. So I think calling it 'save and download as' would be confusing (e.g. is that '(save and download) as'?)
I'm not convinced about building it dynamically: I think there will be exporters exposed that you don't necessarily want in the menu, in which case it's an extra level of complexity to configure which ones are exposed. We may later want to dynamically list some options depending on whether the tools are there to support it (e.g. list PDF if LaTeX is installed), but I think that's best done in a separate PR.
I suppose one could look at the key in |
Need a rebase also. |
The 'print preview' option, just above the submenu, will open the HTML view in a new window/tab, without downloading it. |
@minrk, the conflict here is with your PR to add raw_mimetype metadata to raw cells, and pass them through the relevant exporters. We've both add a mime type traitlet to exporters, with a few differences:
Are there any situations where |
Let's look at the specific use cases:
Currently, I don't think there are any cases where I think we can replace |
Even if you want to save it for another PR, I think the appropriate request for this would be
to list available formats. |
Certainly, I would like to have available "all" the options we currently support in nbconvert... |
<li class="dropdown-submenu"><a href="#">Download as</a> | ||
<ul class="dropdown-menu"> | ||
<li id="download_ipynb"><a href="#">IPython Notebook (.ipynb)</a></li> | ||
<!-- <li id="download_py"><a href="#">Python (.py)</a></li> --> | ||
<li id="download_py"><a href="#">Python (.py)</a></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is is really necessary to add the extensions for each available options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but I like it - it makes it clear what you're getting.
Rebased, condensed the mime type information on nbconvert exporters as Min suggested, and added |
Added a whatsnew entry. |
What does this do if I have not installed pandoc? |
Fail :) |
refs #4655 |
We need to alert to the user in some way... maybe an alert or something like that... |
I talked with Min about what we can do to fail more informatively. He reckons we should copy across the error pages that nbviewer uses, which include details about the failure. To make room for that (which will happen in a separate PR), I've made the 'download as' links open in a new tab, so that we don't navigate the user away from the interactive notebook view if the conversion fails. The downside of that is that if it succeeds, the user sees a brief flash of a new tab opening and closing before the browser offers the download. |
I am stuck grading today but will try to review this tomorrow. I have some On Wed, Dec 11, 2013 at 3:39 PM, Thomas Kluyver notifications@github.comwrote:
Brian E. Granger |
We discussed doing it all through a JSON API, but base64 encoding massive blobs of content to stick them in a JSON structure seems distinctly icky. One possibility that I advanced is having the big blob as the body of the HTTP response, with JSON metadata in an HTTP header ( |
I haven't looked the code yet, but does this create a separate HTTP server for nbconvert or just extend the RESTful API of the notebook server? -Just wondering if one can start a standalone nbconvert service without the notebook... |
This just adds handlers to the regular notebook server. AIUI, you could quite easily write a server that would only expose some of the handlers of the main notebook server. |
OK, quick grading break...here is a summary of my idea - largely inspired
Thoughts? On Wed, Dec 11, 2013 at 3:50 PM, Jonathan Frederic <notifications@github.com
Brian E. Granger |
Providing a UI to convert from the dashboard should be easy enough in a later PR. I'm -1 on saving the output to a file and reading it back for the response - that seems somewhat backwards. Except of course when it's necessary, as it will be for PDF. |
Agreed with thomas. To take the example of Office, you do "file > export as...". You are not asked to go to the explorer and right click > convert to. Also opening a new page when downloading is ok IMHO, as the conversion is never instantaneous, would it even be possible to show "your notebook is being processed" Envoyé de mon iPhone
|
|
My feeling about that model is that it is a leaky abstraction that will
On Thu, Dec 12, 2013 at 12:13 AM, Matthias Bussonnier <
Brian E. Granger |
This is a slightly worse user experience if it succeeds, because the new tab flashes up before closing again, but it will let us display an informative error page if it fails, without navigating the user away from the interactive notebook view.
Rebased to fix the tests with the changes to the subprocess stream capturing API in #4690. |
I would provide a counter viewpoint to @ellisonbg's view of the exporter/download process, I'm actually hoping that the download process will provide the abstraction necessary to not scare off new users of an IPython system. I plan to give my co-workers their first access to Python via a remote IPython notebook server and being able to provide the ability to download the pdf's without knowing the details of the underlying filesystem (or nbconvert config) would be perfect. Clicking download and then opening the file from a downloads folder feels like a well understood mechanism. |
If I might help to clarify @takluyver 's patch: https://github.com/ipython/ipython/pull/4656/files#diff-5b7a0ba3686e1c37c317732cd6e771fdR82
It looks like the url to download a PDF of a notebook from the notebook server will be something like:
|
The URL would indeed look like that. However, at present, PDF export is done by a post-processor after Latex export, so that wouldn't work. We've been discussing restructuring it as a separate exporter in order to make that work. |
|
||
@web.authenticated | ||
def get(self, format, path='', name=None): | ||
exporter = exporter_map[format]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a constructor, pass config=self.config
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
A few comments inline, but this looks really good. One more little bit: we should check that the right tests are skipped when pandoc is unavailable. As discussed in today's dev meeting, we may want a richer, more configurable way to use nbconvert, but this will be added to |
When people run their own notebook servers (or are using multi-user in the future), would we want to expose a read-only view that doesn't require authentication (without the |
I think we had indended the html render as a read-only view. I think working out the read-only auth needs to be more carefully done than it was before (which was a proof-of-concept never intended to be merged), and that can be a separate PR. |
Also relevant here that we discussed in person, but I haven't written down is better error pages, like we use in nbviewer. This would allow failed renders to include useful information about the failure. This is also a job for another PR. |
Sorry, yeah, was thinking about it but wasn't sure where to bring it up (in this PR, another issue, stored in my brain until I make my own PR). |
I've had a stab at serving multi-file output as zip files. It currently just checks for the presence of any extra files, so both the rst and latex exports will become a zip file if any cells have any output - even text output is saved as That seems suboptimal. Is there a good heuristic for determining what files are needed? Or should the |
After discussion with @minrk, I've made the extract output preprocessor only extract types that don't get embedded in the main output file. This is configurable, but the default is to extract png, jpg, svg and pdf. |
Excellent. Working great here. Now I'll get to work on better error pages as another PR. |
Nbconvert HTTP service
This brings back print preview and 'download as' (currently Python, HTML and reST are in the menu).
New URL patterns:
GET /nbconvert/<format>/path/to/Notebook.ipynb
POST /nbconvert/<format>
with the JSON notebook model as the body data.nbconvert exporters gain a
mime_type
traitlet, used in the HTTP response headers so the browser knows what type of file it's getting.