jupyter-book icon indicating copy to clipboard operation
jupyter-book copied to clipboard

Plotly + pyppeteer [Intermittent failure] when using jb build ... --builder pdfhtml

Open PaulONeillNW opened this issue 1 year ago • 0 comments

I've been using Jupyter book for a while and had no issues, until I started incorporating Plotly visualisations (given their interactivity).

  1. The specific problem occurs when converting the book from html to PDF.
  2. NB I have addressed the common issue of enabling Javascript (as documented in other issues) - so that is taken care of

My Python notebook has a number of cells, several of which are producing graphs in loops - e.g. 10 ~ 20 graphs of different plots. These outputs are driven by data configuration, rather than code, i.e. the list of required graphs are configured as a data frame, which is consumed in a loop to generate multiple charts from a relatively small (separate) dataset..

  1. Whilst investigating the issue, I was paring down my notebook to a separate "test case" notebook - and I discovered that reducing the number of Plotly outputs - caused it to work OK. i.e. rather than generating 10 - 20 graphs say (in a loop) this was reduced to say 3 - 4 in that loop, it started working without any other changes.

  2. In fact, the same notebook, with the same number of graphs to be generated, could randomly fail or succeed. Therefore this does not appear to be a coding issue per se (on my part), given that it works intermittently.

The error message seems to point the finger at pyppeteer - however there doesn't appear to be any settings I can adjust to try to overcome this...

Error Message Finished generating HTML for book... Converting book HTML into PDF... Traceback (most recent call last): File "c:\programdata\anaconda3\lib\site-packages\pyppeteer\execution_context.py", line 99, in evaluateHandle _obj = await self._client.send('Runtime.callFunctionOn', { pyppeteer.errors.NetworkError: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\programdata\anaconda3\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "c:\programdata\anaconda3\lib\runpy.py", line 87, in run_code exec(code, run_globals) File "C:\ProgramData\Anaconda3\Scripts\jb.exe_main.py", line 7, in File "c:\programdata\anaconda3\lib\site-packages\click\core.py", line 829, in call return self.main(*args, **kwargs) File "c:\programdata\anaconda3\lib\site-packages\click\core.py", line 782, in main rv = self.invoke(ctx) File "c:\programdata\anaconda3\lib\site-packages\click\core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "c:\programdata\anaconda3\lib\site-packages\click\core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "c:\programdata\anaconda3\lib\site-packages\click\core.py", line 610, in invoke return callback(*args, **kwargs) File "c:\programdata\anaconda3\lib\site-packages\jupyter_book\cli\main.py", line 323, in build builder_specific_actions( File "c:\programdata\anaconda3\lib\site-packages\jupyter_book\cli\main.py", line 585, in builder_specific_actions html_to_pdf(output_path.joinpath("index.html"), path_pdf_output) File "c:\programdata\anaconda3\lib\site-packages\jupyter_book\pdf.py", line 45, in html_to_pdf asyncio.get_event_loop().run_until_complete(_html_to_pdf(html_file, pdf_file)) File "c:\programdata\anaconda3\lib\asyncio\base_events.py", line 616, in run_until_complete return future.result() File "c:\programdata\anaconda3\lib\site-packages\jupyter_book\pdf.py", line 69, in _html_to_pdf await page.addStyleTag( File "c:\programdata\anaconda3\lib\site-packages\pyppeteer\page.py", line 556, in addStyleTag return await frame.addStyleTag(options) File "c:\programdata\anaconda3\lib\site-packages\pyppeteer\frame_manager.py", line 568, in addStyleTag return (await context.evaluateHandle( # type: ignore File "c:\programdata\anaconda3\lib\site-packages\pyppeteer\execution_context.py", line 108, in evaluateHandle _rewriteError(e) File "c:\programdata\anaconda3\lib\site-packages\pyppeteer\execution_context.py", line 237, in _rewriteError raise type(error)(msg) pyppeteer.errors.NetworkError: Execution context was destroyed, most likely because of a navigation.

Environment
Jupyter Book : 0.12.3 External ToC : 0.2.4 MyST-Parser : 0.15.2 MyST-NB : 0.13.2 Sphinx Book Theme : 0.1.10 Jupyter-Cache : 0.4.3 NbClient : 0.5.13

PaulONeillNW avatar Sep 04 '24 16:09 PaulONeillNW