Skip to content

Inlined HoloViews objects are not rendered #436

@maximlt

Description

@maximlt

Describe the bug

Hi and thanks for this great library, loving it!

I am very tempted to use more and more features of myst-nb and your ecosystem in general to update the HoloViz documentation. One thing I would like to do, and that is the original motivation of this issue, is to use the Tabs component offered by sphinx-design to display in each tab a different plot. This would be for instance very useful for a library like HoloViews that has a Reference Gallery describing each kind of plot that can be made, as this for 3 plotting backends (Bokeh, Matplotlib and Plotly). We currently have a page for each combination of plot type and plotting backend, and would be happy to reduce that to one page by plot type, having in each page Tabs components that show how the plot renders with the 3 plotting backends.

I've made some experiment with sphinx-design and found out that code-cell directives cannot be nested in other directives. I believe this is the same issue as reported here (jupyter-book/jupyter-book#1178) and I understand this is by design, it makes sense to me.

I have then found out about the inlining feature of myst-nb and thought that I could use that as a nice workaround! And indeed starting from a simple example, inlining a simple string variable, I came to the conclusion that this could work.

However, inlining a HoloViews object - the type of object returned by hvPlot - didn't seem to work even if the code-cell displayed it correctly.

image

In case you would try building this example by yourself, I've seen this warning being emitted while the code-cell is rendered (i.e. without having any inline). I don't think it's harmful though.
WARNING: skipping unknown output mime type: application/vnd.holoviews_load.v0+json [mystnb.unknown_mime_type]

Happy to provide details on the HoloViews displaying machinery if needed, and if this issue is way too tailored to the HoloViz ecosystem I'd welcome any pointers for us to fix that by ourselves.

Reproduce the bug

  • Create an environment and install the dependencies with pip install pandas hvplot or conda install pandas hvplot
  • Copy the content below in a Markdown file and build the docs with myst-nb:
---
file_format: mystnb
kernelspec:
  name: python3
mystnb:
    execution_mode: 'inline'
---

# Text-based Notebook hvPlot

## Display from a code cell: OK

:::{code-cell} ipython3
import pandas as pd, numpy as np
import hvplot.pandas  # noqa
idx = pd.date_range('1/1/2000', periods=1000)
df  = pd.DataFrame(np.random.randn(1000, 4), index=idx, columns=list('ABCD')).cumsum()

p = df.hvplot()
p
:::


## Display from an inlined eval: not OK

HoloViews obj: {eval}`p`

List your environment

myst-nb                   0.16.0             pyhd8ed1ab_0    conda-forge
myst-parser               0.18.0             pyhd8ed1ab_0    conda-forge

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions