Description
Symptom: when running the following conversion on a notebook that produces a plot in the first cell:
PLOTLY_RENDERER=iframe_connected jupyter nbconvert --execute --to html --no-input my_notebook.ipynb
the following error is received:
File ~/.virtualenvs/myenv/lib/python3.9/site-packages/plotly/io/_base_renderers.py:612, in IFrameRenderer.build_filename(self)
610 def build_filename(self):
611 ip = IPython.get_ipython() if IPython else None
--> 612 cell_number = list(ip.history_manager.get_tail(1))[0][1] + 1 if ip else 0
613 filename = "{dirname}/figure_{cell_number}.html".format(
614 dirname=self.html_directory, cell_number=cell_number
615 )
616 return filename
IndexError: list index out of range
The iframe renderer saves plots to a separate file and the filename is supposed to be based off the current cell number. The line of code that retrieves this cell number makes use of the IPython HistoryManager.get_tail method which, by default, returns the already executed cells, not the currently executing cell. When within the first cell it therefore returns an empty list and this is what causes the 'list index our of range'. The fix is very simple: add include_latest=True to the get_tail call so that the currently executing cell is returned instead of the previous one.
Meanwhile a simple workaround is to always include a cell that does not produce a plot at the start of the notebook.