From a639f14b941ca5626c623be869414187a180ea35 Mon Sep 17 00:00:00 2001 From: Frans van der Meer Date: Mon, 5 Jan 2026 20:16:03 +0100 Subject: [PATCH] Update plotly HTML instructions --- book/features/plotly.ipynb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/book/features/plotly.ipynb b/book/features/plotly.ipynb index 8f81598..7f92684 100644 --- a/book/features/plotly.ipynb +++ b/book/features/plotly.ipynb @@ -32,16 +32,12 @@ "metadata": {}, "outputs": [], "source": [ - "from IPython import get_ipython\n", + "import os\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", + " # Use HTML when building book in CI environment\n", + " if os.environ.get(\"CI\") == \"true\":\n", " return HTML(fig.to_html(include_plotlyjs=\"cdn\"))\n", "\n", " # Local execution in Jupyter Notebook / JupyterLab / VS Code\n", @@ -70,7 +66,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "When using Plotly graphs, make sure the notebook is executed in Jupyter Lab / Jupyter Notebook for the figures to be shown in the book. Running the code in VS code might break the result in the book, although the output is visible in VS code. Alternatively, add the following lines of code to your notebook to have a valid output in the book as well:\n", + "Alternatively, you can run the notebook locally before building the book. This is not recommended for the combination with git because you will be committing binary output to the repository. When pre-generating Plotly graphs, make sure the notebook is executed in Jupyter Lab / Jupyter Notebook for the figures to be shown in the book. Running the code in VS code might break the result in the book, although the output is visible in VS code. Add the following lines of code to your notebook to have a valid output in the book as well:\n", "\n", "```python\n", "import plotly.io as pio\n",