-
Notifications
You must be signed in to change notification settings - Fork 86
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
Allow Bokeh plots to be glued and pasted #335
Conversation
Using the JSON-type output from Bokeh, this creates appropriate HTML and Javascript nodes in the output when the Bokeh+JSON mimetype is found. The Python Bokeh library is only imported when it is needed, to avoid a package dependency on Bokeh. Users will need to install Bokeh via pip or conda to be able to glue/paste Bokeh plots. Using the JSON output allows plots to be pasted into figures as well as a general element with no further changes. Uses the Sphinx configuration to decide whether a page has Bokeh content and only loads BokehJS on those pages. This simplifies the script that needs to be embedded in each paste and ensures that Bokeh is only loaded once from the CDN, unless the user runs output_notebook(). In the case where the user runs output_notebook() the BokehJS library is loaded twice but this doesn't appear to cause any problems.
@choldgraf @chrisjsewell, I am interested to know your thoughts about adding pieces like this one that interfaces with 3rd party libraries. There is some preliminary conversation on the following previous discussion (in case you need some context): executablebooks/meta#346. |
Hey @bryanwweber @damianavila 👋🏼 Essentially I feel these third party interfaces to myst-nb (and thus jupyter-book) should probably be in a separate plugin package, and loaded via entry points this is already possible via |
Thanks @chrisjsewell Any pointers to how to do that in the docs or elsewhere? |
@bryanwweber there are some docs here: https://myst-nb.readthedocs.io/en/latest/use/formatting_outputs.html#customise-the-render-process but this one might be a test-case that drives some enhancements to the documentation (e.g., maybe a short tutorial on implementing your own renderer) I am happy to help write out some steps on how to do this, I think this would be a great way to extend MyST-NB's functionality without adding a lot of complexity to the core (e.g., For reference, here's load_renderer function: MyST-NB/myst_nb/render_outputs.py Line 70 in a4c21b1
and here's where the entry points are defined: Line 62 in ce5f69c
|
@choldgraf @chrisjsewell Thanks for the references, I'll look into it! I certainly appreciate the desire to keep the core of MyST-NB small! 😄 It seems like this plugin would solve the rendering issue, but not the glueing issue. Using the current I think glueing a Bokeh figure would then require a separate function (e.g., Do you have any thoughts/opinions about that idea? Thanks! |
@choldgraf @chrisjsewell OK, so I tried this approach of loading a renderer from an entry point. Unfortunately, this does not allow pasting either, because the renderer is always set to MyST-NB/myst_nb/nb_glue/domain.py Line 44 in e39132e
If I change that string to point to my new renderer entry point, then it works 🎉 So this is going to definitely require changes to |
@choldgraf @chrisjsewell I'm going to close this. I created an extension package over here: https://github.com/bryanwweber/MyST-NB-Bokeh I'll do some more cleanup and add testing in the next little while. I'll make a separate PR for the fix to MyST-NB that's needed to get it working properly, as I mentioned above ☝️ FWIW, the documentation was not super helpful in creating this. I'd be happy to write up a blog post/bit of documentation about how I got all this working. Let me know what's the best place for that. Thanks for the pointers! |
Heya yeh no worries cheers |
@choldgraf, what would be a good place for this? I do not want to lose the generated momentum created by @bryanwweber 😉 |
Btw, that PR lives here (crosslinking for easier ref): #337 |
Using the JSON-type output from Bokeh, this creates appropriate HTML and
Javascript nodes in the output when the Bokeh+JSON mimetype is found.
The Python Bokeh library is only imported when it is needed, to avoid a
package dependency on Bokeh. Users will need to install Bokeh via pip or
conda to be able to glue/paste Bokeh plots. Using the JSON output allows
plots to be pasted into figures as well as a general element with no
further changes.
Uses the Sphinx configuration to decide whether a page has Bokeh content
and only loads BokehJS on those pages. This simplifies the script that
needs to be embedded in each paste and ensures that Bokeh is only loaded
once from the CDN, unless the user runs output_notebook(). In the case
where the user runs output_notebook() the BokehJS library is loaded
twice but this doesn't appear to cause any problems.