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

Panel serve trips over code in raw cells #611

Closed
poplarShift opened this issue Aug 21, 2019 · 7 comments
Closed

Panel serve trips over code in raw cells #611

poplarShift opened this issue Aug 21, 2019 · 7 comments
Labels
TRIAGE

Comments

@poplarShift
Copy link
Contributor

@poplarShift poplarShift commented Aug 21, 2019

The following notebook cannot be served using panel serve while working ok as notebook as such:
(Code cell:)

import panel as pn
pn.extension()
app = pn.Row('SPAM')
app.servable()

(Raw cell:)

some = invalid python code

Note that if the raw cell is changed to foo it seems to work.

@poplarShift poplarShift added the TRIAGE label Aug 21, 2019
@jbednar
Copy link
Member

@jbednar jbednar commented Aug 21, 2019

According to the ipython docs, a raw cell is intended for inclusion as-is when nbconvert is used to create output of the type of that raw cell. Here, if it's a raw Python cell, then that code is ignored by the notebook but is included when output as Python, which is essentially what panel serve is doing. It seems valid to me to use this mechanism to pass some additional Python code into the file when Panel converts it to Python, which appears to be happening here, so I'm not sure what the problem is -- if you don't want the raw cell's code to be executed, why have it there? It all seems to be working as designed, but I may be missing something.

@poplarShift
Copy link
Contributor Author

@poplarShift poplarShift commented Aug 21, 2019

I wasn't necessarily saying it's a bug but it had me confused for a while. The docs do sound like all panel serve cares about is the python code but now I see they launch the "entire" notebook including the raw content.

(I guess I belong to those who (ab)use raw cells as a shorthand for commenting out groups of cells (a single push on r is much easier than entering each of them and going ctrl-a ctrl-/) but in hindsight I realize that may not even be common usage.)

@jbednar
Copy link
Member

@jbednar jbednar commented Aug 21, 2019

Ok, that makes sense. When you hit r, it designates the cell as raw without specifying the type, and the docs indicate that such text should be included in all nbconvert output. I'm not sure how useful that convention is, given that few (if any) strings will be valid for all nbconvert targets, but that's what it's supposed to do. The upshot is if that if you use r to mark cells not to be parsed by the notebook editor, you're making the notebook unusable by anything based on nbconvert, including Panel.

We could add a special case to ignore untyped NBConvert raw cells, but that seems like an arbitrary thing to do, and would cause problems for any user who expected untyped raw cells to work as they were designed. If there are tons of people who see this issue and habitually use r in this way, so much that they drown out any people who use it as designed, then we could reconsider, but meanwhile I think you'll have to wean yourself from r if you want to use the notebook anywhere but the native notebook interface. :-)

@poplarShift
Copy link
Contributor Author

@poplarShift poplarShift commented Aug 22, 2019

No, I'm all for leaving behaviour as is. But maybe the docs could be more specific about how panel serve works in this regard? E.g., when I go jupyter nbconvert --execute, raw cells get ignored too, so panel serve's behaviour wasn't obvious to me (let alone the fact that panel serve is based off nbconvert). Though then again it probably makes a lot more sense to someone who's more familiar with the inner workings of notebooks than me :)

@jlstevens
Copy link
Contributor

@jlstevens jlstevens commented Aug 22, 2019

I agree this needs to be explained better in the docs. For completeness, what happens is this:

  • panel serve is really just a minor extension to bokeh serve.
  • bokeh serve uses nbconvert.PythonExporter() (see here) with a preprocessor to strip out magics.

In other words, the behavior wrt the code executed is the same as the following, just with magics stripped:

jupyter nbconvert notebook.ipynb --to python

This means there is no mention of raw cells in either panel or bokeh: the behavior with respect to raw cells is down to how nbconvert turns notebooks into Python code.

@jbednar
Copy link
Member

@jbednar jbednar commented Aug 22, 2019

Thanks, Jean-Luc. @poplarShift , we'd be happy to see a PR where this is explained in the docs where it could help users avoid the confusion you had.

poplarShift added a commit to poplarShift/panel that referenced this issue Aug 22, 2019
poplarShift added a commit to poplarShift/panel that referenced this issue Aug 22, 2019
@poplarShift
Copy link
Contributor Author

@poplarShift poplarShift commented Aug 22, 2019

Thanks @jlstevens and @jbednar for the explanations. I summarized the info you gave here and added a little paragraph in the docs.

philippjfr pushed a commit that referenced this issue Aug 23, 2019
philippjfr pushed a commit that referenced this issue Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TRIAGE
Projects
None yet
Development

No branches or pull requests

3 participants