-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
first pass at nteract support #562
Conversation
Here's a first pass at offline interact support. Here's a comment in the commit for some details:
|
Associated nteract PR: nteract/nteract#662 |
plotly/offline/offline.py
Outdated
# Both of these bundles will be saved as part of the notebook. The renderer | ||
# will choose which one to render. So 'text/html' is like a fallback for | ||
# any environment that doesn't have the 'application/json+plotly.v1' | ||
# renderer available. |
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.
Cool, yah, this makes sense to me. Agreed that notebooks getting bigger is a bummer... I'm not sure how much of an edge case that is.
Tried out |
Ah, here we go. Pretty explicit in the schema here if not the intention. If it's a custom mimetype it expects an array of strings or a string. |
I suppose we'd need the notebook schema to also have:
for JupyterLab/ipywidgets:
|
Current proposal for registering custom mimetypes in nteract: nteract/nteract#670 |
Not quite sure where your thinking is right now, are you going in the direction of extending the nb schema? |
I'd like to pick the right future direction while not crippling usage of the classic notebook. There are quite a few options here, so I was outlining some thoughts on them. |
Got it. I guess once this is a bit more fleshed out, would be good to run it by the Jupyter list for broader thoughts. |
Yeah, I'll make an outline in an email on the jupyter list. It's working quite nicely in nteract, and I'm working on vega support, soon bokeh as well. |
Beyond that though, it seems like the only way for us to do custom extensions is to make them be double encoded JSON in the current schema. Only the pure field |
Per resolution in jupyter/nbformat#43, the plotly mimetype should be |
Since jupyter/nbformat#42 has been merged we can now send over the raw JSON on the next nbformat release. However, since users of old versions of the notebook should allow this to still work, we can send the serialized JSON as a string directly, which was handled for backwards compatibility in nteract here: https://github.com/nteract/nteract/pull/675/files#diff-18d3d49b31452599ff46a67c571aa4f8R7 One other thing that still needs to be changed is that the mimetype should now be |
@theengineear - online mode works fine, this would just be for offline support. it doesn't seem like there is any getting around this, so it seems like it's something that we should just add. thoughts? |
+1 from me. We can't really promote nteract too much without offline mode working. We'd just get too many support Q's. |
plotly/offline/offline.py
Outdated
# The upside is that we're dropping any compatability for older notebook | ||
# versions | ||
display_bundle = { | ||
'application/json+plotly.v1': { |
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.
@chriddyp I believe this needs to be updated now (as per #562 (comment)) to application/vnd.plotly.v1+json
.
^^ weird, |
hrm... I think there's something off with how other tests are getting We should have our This will likely take a little while since a lot of our tests are still written in ☕️ ☕️ ☕️ It's worth getting this correct now, we keep running into these issues. Really, fewer of our tests should even be hitting a Ideally, we'd just totally mock out the Python API and setup a suite of API tests inside the |
@chriddyp @rgbkrk I got tests passing and AFAIK offline mode is working as expected: Anything else to be done here? I'm a little booked up on other tasks and don't want to let this linger much longer. //cc @jackparmer |
^^ That's this nteract version |
Sorry to keep pinging, but are we all good with this @chriddyp? Anything else you wanted to add? |
It's got my 💃 :) |
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.
Cool to see this moving forward!
plotly/offline/offline.py
Outdated
@@ -273,7 +273,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', | |||
validate=True, image=None, filename='plot_image', image_width=800, | |||
image_height=600): | |||
""" | |||
Draw plotly graphs inside an IPython notebook without | |||
Draw plotly graphs inside an IPython or Jupter notebook without |
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.
s/Jupter/Jupyter/
plotly/offline/offline.py
Outdated
# - The raw HTML is the "old-school" style - we just throw in a JS script | ||
# inside the cell. This works for a lot of environments but some JS is | ||
# stripped out in some rendering environments / platforms like | ||
# GitHub, nteract, and eventually Plotly |
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.
JavaScript is not stripped out in nteract - the core differences are that:
require
is commonjs require rather than requirejs' require in the desktop app- we don't have the same JavaScript API as the Jupyter notebook
Neither of those should be relied on for HTML outputs regardless (or at least some primitive feature detection and fallbacks need to happen).
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 ended up just 🔪-ing a lot of that comment out, I don't think it needs to get committed here.
plotly/offline/offline.py
Outdated
# GitHub, nteract, and eventually Plotly | ||
# - The custom `mime-types` is the new-school way. nteract supports | ||
# rendering plotly graphs this way (see https://github.com/nteract/nteract/pull/662) | ||
# and others will hopefully follow suite. |
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.
s/follow suite/follow suit/
1. no side effect files from running tests 2. don’t auto-open plot in browser, it auto-focuses and is incredibly distracting when multi-tasking.
Clean-slates each test. It doesn’t mean that the files aren’t dirty between tests, but because `session` takes precedence, this helps a lot.
looks great to me, this is awesome! 💃 |
@chriddyp Did you find a way around this ? Or, do notebooks with multiple mime types just have to be larger ? |
They only have to be larger if you wish to support old versions of the notebooks. |
Thanks for the quick response @rgbkrk. Sorry, rephrasing my question, "Notebooks with custom mime-types which also have to be used with nbviewer just have to be larger? " I guess that is a question to be asked in the nbconvert/nbviewer repo. |
Someone would have to add support to nbconvert and nbviewer, that's for sure. |
I'll take a shot. Ipywidgets render in nbviewer by fetching the widget models and views from unpkg, and i think even this can now be configured. Maybe a similar strategy for fetching mime-renderers from somewhere..? Anyway, I'll open a ticket for discussion. Thanks a lot. :) |
No description provided.