jupyter-book
jupyter-book copied to clipboard
Plotly rendering does not work due to unknown output mime type
Describe the bug
context When I do try to execute a code cell that show a plotly figure, e.g the code snippet from https://jupyterbook.org/en/stable/interactive/interactive.html?highlight=mime#plotly, i.e
import plotly.io as pio
import plotly.express as px
import plotly.offline as py
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size="sepal_length")
fig
using jupyter-book
version 0.14
expectation I expected the book build successfully.
bug But instead I get the following error
root@c2d8bf9fa631:/shared# jupyter-book build -W docs
Running Jupyter-Book v0.14.0
Source Folder: /shared/docs
Config Path: /shared/docs/_config.yml
Output Path: /shared/docs/_build/html
Running Sphinx v5.0.2
making output directory... done
[etoc] Changing master_doc to 'intro'
checking bibtex cache... out of date
parsing bibtex file /shared/docs/references.bib... parsed 5 entries
myst v0.18.1: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions=['colon_fence', 'dollarmath', 'linkify', 'substitution', 'tasklist'], disable_syntax=[], all_links_external=False, url_schemes=['mailto', 'http', 'https'], ref_domains=None, highlight_code_blocks=True, number_code_blocks=[], title_to_header=False, heading_anchors=None, heading_slug_func=None, footnote_transition=True, words_per_minute=200, sub_delimiters=('{', '}'), linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area')
myst-nb v0.17.1: NbParserConfig(custom_formats={}, metadata_key='mystnb', cell_metadata_key='mystnb', kernel_rgx_aliases={}, execution_mode='force', execution_cache_path='', execution_excludepatterns=[], execution_timeout=30, execution_in_temp=False, execution_allow_errors=False, execution_raise_on_error=False, execution_show_tb=False, merge_streams=False, render_plugin='default', remove_code_source=False, remove_code_outputs=False, code_prompt_show='Show code cell {type}', code_prompt_hide='Hide code cell {type}', number_source_lines=False, output_stderr='show', render_text_lexer='myst-ansi', render_error_lexer='ipythontb', render_image_options={}, render_figure_options={}, render_markdown_format='commonmark', output_folder='build', append_css=True, metadata_to_fm=False)
Using jupyter-cache at: /shared/docs/_build/.jupyter_cache
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 4 source files that are out of date
updating environment: [new config] 4 added, 0 changed, 0 removed
/shared/docs/markdown-notebooks.md: Executing notebook using local CWD [mystnb]
/shared/docs/markdown-notebooks.md: Executed notebook in 0.86 seconds [mystnb]
/shared/docs/notebooks.ipynb: Executing notebook using local CWD [mystnb]
/shared/docs/notebooks.ipynb: Executed notebook in 1.24 seconds [mystnb]
Warning, treated as error:
/shared/docs/notebooks.ipynb:20002:skipping unknown output mime type: application/vnd.plotly.v1+json [mystnb.unknown_mime_type]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/jupyter_book/sphinx.py", line 171, in build_sphinx
app.build(force_all, filenames)
File "/usr/local/lib/python3.10/dist-packages/sphinx/application.py", line 329, in build
self.builder.build_update()
File "/usr/local/lib/python3.10/dist-packages/sphinx/builders/__init__.py", line 288, in build_update
self.build(to_build,
File "/usr/local/lib/python3.10/dist-packages/sphinx/builders/__init__.py", line 301, in build
with logging.pending_warnings():
File "/usr/lib/python3.10/contextlib.py", line 142, in __exit__
next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/sphinx/util/logging.py", line 217, in pending_warnings
memhandler.flushTo(logger)
File "/usr/local/lib/python3.10/dist-packages/sphinx/util/logging.py", line 182, in flushTo
logger.handle(record)
File "/usr/lib/python3.10/logging/__init__.py", line 1634, in handle
self.callHandlers(record)
File "/usr/lib/python3.10/logging/__init__.py", line 1696, in callHandlers
hdlr.handle(record)
File "/usr/lib/python3.10/logging/__init__.py", line 964, in handle
rv = self.filter(record)
File "/usr/lib/python3.10/logging/__init__.py", line 821, in filter
result = f.filter(record)
File "/usr/local/lib/python3.10/dist-packages/sphinx/util/logging.py", line 425, in filter
raise exc
sphinx.errors.SphinxWarning: /shared/docs/notebooks.ipynb:20002:skipping unknown output mime type: application/vnd.plotly.v1+json [mystnb.unknown_mime_type]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/bin/jupyter-book", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/jupyter_book/cli/main.py", line 317, in build
builder_specific_actions(
File "/usr/local/lib/python3.10/dist-packages/jupyter_book/cli/main.py", line 525, in builder_specific_actions
raise RuntimeError(_message_box(msg, color="red", doprint=False)) from result
RuntimeError:
===============================================================================
There was an error in building your book. Look above for the cause.
===============================================================================
Reproduce the bug
- Install jupyter-book and plotly (and pandas)
pip install jupyter-book plotly pandas
- Create a new book
jupyter-book create docs
- In
docs/notebooks.ipynb
remove the matplotlib example and add the a new code cell with the following content
import plotly.io as pio
import plotly.express as px
import plotly.offline as py
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size="sepal_length")
fig
- Build book
jupyter-book build docs
List your environment
Python3.10 in Ubuntu docker image
Docker file
FROM ubuntu:jammy
RUN apt update && apt install -y python3-dev python3-pip
RUN python3 -m pip install jupyter-book plotly pandas
Output from pip list
Package Version
----------------------------- ---------
alabaster 0.7.13
asttokens 2.2.1
attrs 22.2.0
Babel 2.12.1
backcall 0.2.0
beautifulsoup4 4.11.2
certifi 2022.12.7
charset-normalizer 3.0.1
click 8.1.3
comm 0.1.2
debugpy 1.6.6
decorator 5.1.1
docutils 0.18.1
executing 1.2.0
fastjsonschema 2.16.3
greenlet 2.0.2
idna 3.4
imagesize 1.4.1
importlib-metadata 6.0.0
ipykernel 6.21.2
ipython 8.11.0
jedi 0.18.2
Jinja2 3.1.2
jsonschema 4.17.3
jupyter-book 0.14.0
jupyter-cache 0.5.0
jupyter_client 8.0.3
jupyter_core 5.2.0
latexcodec 2.0.1
linkify-it-py 2.0.0
markdown-it-py 2.2.0
MarkupSafe 2.1.2
matplotlib-inline 0.1.6
mdit-py-plugins 0.3.4
mdurl 0.1.2
myst-nb 0.17.1
myst-parser 0.18.1
nbclient 0.5.13
nbformat 5.7.3
nest-asyncio 1.5.6
numpy 1.24.2
packaging 23.0
pandas 1.5.3
parso 0.8.3
pexpect 4.8.0
pickleshare 0.7.5
pip 22.0.2
platformdirs 3.0.0
plotly 5.13.1
prompt-toolkit 3.0.38
psutil 5.9.4
ptyprocess 0.7.0
pure-eval 0.2.2
pybtex 0.24.0
pybtex-docutils 1.0.2
pydata-sphinx-theme 0.12.0
Pygments 2.14.0
pyrsistent 0.19.3
python-dateutil 2.8.2
pytz 2022.7.1
PyYAML 6.0
pyzmq 25.0.0
requests 2.28.2
setuptools 59.6.0
six 1.16.0
snowballstemmer 2.2.0
soupsieve 2.4
Sphinx 5.0.2
sphinx-book-theme 0.4.0rc1
sphinx-comments 0.0.3
sphinx-copybutton 0.5.1
sphinx_design 0.3.0
sphinx_external_toc 0.3.1
sphinx-jupyterbook-latex 0.5.2
sphinx-multitoc-numbering 0.1.3
sphinx-thebe 0.2.1
sphinx-togglebutton 0.3.2
sphinxcontrib-applehelp 1.0.4
sphinxcontrib-bibtex 2.5.0
sphinxcontrib-devhelp 1.0.2
sphinxcontrib-htmlhelp 2.0.1
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 1.0.3
sphinxcontrib-serializinghtml 1.1.5
SQLAlchemy 1.4.46
stack-data 0.6.2
tabulate 0.9.0
tenacity 8.2.2
tornado 6.2
traitlets 5.9.0
typing_extensions 4.5.0
uc-micro-py 1.0.1
urllib3 1.26.14
wcwidth 0.2.6
wheel 0.37.1
zipp 3.15.0
Note that I also tried this on Mac, but in that case I did not get any errors, so I suspect it is only an issue on Linux
I'd would note, it works exactly the same as it did before, it just does not silently ignore application/vnd.plotly.v1+json
You can simply suppress the warning https://myst-nb.readthedocs.io/en/latest/configuration.html#myst-error-reporting
Thanks @chrisjsewell. Indeed, adding the following lines
sphinx:
config:
suppress_warnings: ["mystnb.unknown_mime_type"]
to _config.yml
makes the problem go away. However, I would argue that I think this should be the default behaviour for jupyter-book to suppress this warning. At least, it should be added to the documentation. I will happy to contribute a PR adding this to the documentation is this is wanted?
I would argue that I think this should be the default behaviour for jupyter-book to suppress this warning
The problem with that, is there is no way to "unsupress" warnings, so then you would never know there is a potential problem. Also warnings are exactly that, just warnings, they shouldn't be inherently fatal to the build. My recommended way of running sphinx/jupyter-book is:
jupyter-book build -nW --keep-going docs
I think this is already in the documentation?
I will happy to contribute a PR adding this to the documentation is this is wanted?
PRs are always welcome!
Note similar sections in https://myst-parser.readthedocs.io/en/stable/configuration.html#build-warnings and https://myst-nb.readthedocs.io/en/latest/configuration.html#warning-suppression
This was so useful! Thanks for flagging it @finsberg