From 025b2ff5c72611faf269ac6b47d3d571610a1238 Mon Sep 17 00:00:00 2001 From: Tom van Woudenberg Date: Fri, 19 Dec 2025 13:32:17 +0100 Subject: [PATCH] Update plotyl instructions --- book/features/plotly.ipynb | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/book/features/plotly.ipynb b/book/features/plotly.ipynb index 6852a21..08005fc 100644 --- a/book/features/plotly.ipynb +++ b/book/features/plotly.ipynb @@ -437,6 +437,58 @@ "\n", "fig.show()" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you want to create the plot during the build of the book, don't use `fig.show()` but use the code below:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython import get_ipython\n", + "from IPython.display import HTML\n", + "\n", + "def show_plotly(fig):\n", + " ip = get_ipython()\n", + " if ip is None:\n", + " return fig\n", + "\n", + " # Sphinx / Jupyter Book execution\n", + " if \"sphinx\" in ip.config:\n", + " return HTML(fig.to_html(include_plotlyjs=\"cdn\"))\n", + "\n", + " # Local execution in Jupyter Notebook / JupyterLab / VS Code\n", + " fig.show()\n", + "\n", + "....\n", + "\n", + "show_plotly(fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make sure you have in your `_config.yml`:\n", + "\n", + "```yaml\n", + "execute:\n", + " execute_notebooks: \"auto\"\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Eventually in combination with [](../_git/github.com_TeachBooks_Sphinx-NB-Execution-Patterns/Manual/README.html)" + ] } ], "metadata": {