Error displaying Pyvis HTML inside Jupyter Lab cell
Asked Answered
M

2

6

I'm using the Pyvis library to generate and display a network inside Jupyter Lab (in a cell) through the HTML format. I have managed to create the file and open it externally (with the Pyvis save_graph function). However, when using the net.Network(notebook=True) option from Pyvis, Jupyter outputs:

404 : Not Found.
You are requesting a page that does not exist!

While the terminal (from where I launch Jupyter) outputs:

404 GET /files/Documents/(Git)%20Projects/SimSalar/Jupyter%20Notebooks/TRIAL2.html?_xsrf=2%7C9665d25e%7Cbc3fea246105c6b3a9d39f6bbb10d512%7C1607563598&1609770942196 (::1) 1.29ms referer=http://localhost:8888/lab/tree/Documents/(Git)%20Projects/SimSalar/Jupyter%20Notebooks/Workshop%20Analysis.ipynb

The code to get this error, from the Pyvis documentation, is pretty straightforward:

import networkx as nx
from pyvis import network as net

g = net.Network(notebook=True)
nxg = nx.complete_graph(5)
g.from_nx(nxg)
g.show('TRIAL2.html')

Just to clarify, the HTML file is created without any issue (and thus can be opened externally), the problem lies on displaying this file inside JupyterLab (in the cell). I have reinstalled Jupyter multiple times, and used several versions of Jupyter Lab (2.4; 2.6; and 3.0 now). I leave below the full conda environment specifications. I have also given different paths to the g.show('TRIAL2.html') function with the OS module. However, it still does not works.

# Name                    Version                   Build  Channel
anyio                     2.0.2            py39h6e9494a_3    conda-forge
appnope                   0.1.2            py39h6e9494a_0    conda-forge
argon2-cffi               20.1.0           py39h5a22ff9_2    conda-forge
async_generator           1.10                       py_0    conda-forge
attrs                     20.3.0             pyhd3deb0d_0    conda-forge
babel                     2.9.0              pyhd3deb0d_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.1                      py_0    conda-forge
bleach                    3.2.1              pyh9f0ad1d_0    conda-forge
brotlipy                  0.7.0           py39h66d5b7b_1001    conda-forge
ca-certificates           2020.12.8            hecd8cb5_0  
certifi                   2020.12.5        py39h6e9494a_0    conda-forge
cffi                      1.14.4           py39h7786acb_1    conda-forge
chardet                   4.0.0            py39h6e9494a_0    conda-forge
cryptography              3.3.1            py39h79a2c39_0    conda-forge
cycler                    0.10.0                     py_2    conda-forge
decorator                 4.4.2                      py_0    conda-forge
defusedxml                0.6.0                      py_0    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
freetype                  2.10.4               h3f75d11_0    conda-forge
icu                       68.1                 h74dc148_0    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
importlib-metadata        3.3.0            py39h6e9494a_2    conda-forge
importlib_metadata        3.3.0                hd8ed1ab_2    conda-forge
ipykernel                 5.4.2            py39h71a6800_0    conda-forge
ipython                   7.19.0           py39h71a6800_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.6.2              pyhd3deb0d_0    conda-forge
jedi                      0.18.0           py39h6e9494a_1    conda-forge
jinja2                    2.11.2             pyh9f0ad1d_0    conda-forge
jpeg                      9d                   hbcb3906_0    conda-forge
json5                     0.9.5              pyh9f0ad1d_0    conda-forge
jsonpickle                1.4.2              pyhd3eb1b0_0  
jsonschema                3.2.0                      py_2    conda-forge
jupyter_client            6.1.7                      py_0    conda-forge
jupyter_core              4.7.0            py39h6e9494a_0    conda-forge
jupyter_server            1.1.3            py39h6e9494a_0    conda-forge
jupyterlab                3.0.0              pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
jupyterlab_server         2.0.0              pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        1.0.0              pyhd8ed1ab_1    conda-forge
kiwisolver                1.3.1            py39heea7e63_0    conda-forge
lcms2                     2.11                 h11f7e16_1    conda-forge
libblas                   3.9.0                6_openblas    conda-forge
libcblas                  3.9.0                6_openblas    conda-forge
libcxx                    11.0.0               h4c3b8ed_1    conda-forge
libffi                    3.3                  h046ec9c_2    conda-forge
libgfortran               5.0.0               h6c81a4c_15    conda-forge
libgfortran5              9.3.0               h6c81a4c_15    conda-forge
liblapack                 3.9.0                6_openblas    conda-forge
libopenblas               0.3.12          openmp_h54245bb_1    conda-forge
libpng                    1.6.37               h7cec526_2    conda-forge
libsodium                 1.0.18               hbcb3906_1    conda-forge
libtiff                   4.2.0                h355d032_0    conda-forge
libuv                     1.40.0               h35c211d_0    conda-forge
libwebp-base              1.1.0                hbcb3906_3    conda-forge
llvm-openmp               11.0.0               h73239a0_1    conda-forge
lz4-c                     1.9.3                h046ec9c_0    conda-forge
markupsafe                1.1.1            py39h66d5b7b_2    conda-forge
matplotlib                3.3.3            py39h6e9494a_0    conda-forge
matplotlib-base           3.3.3            py39h5674cf4_0    conda-forge
mistune                   0.8.4           py39h5a22ff9_1002    conda-forge
nbclassic                 0.2.5              pyhd8ed1ab_0    conda-forge
nbclient                  0.5.1                      py_0    conda-forge
nbconvert                 6.0.7            py39h6e9494a_3    conda-forge
nbformat                  5.0.8                      py_0    conda-forge
ncurses                   6.2                  h2e338ed_4    conda-forge
nest-asyncio              1.4.3              pyhd8ed1ab_0    conda-forge
networkx                  2.5                        py_0    conda-forge
nodejs                    15.3.0               heaeed3d_0    conda-forge
notebook                  6.1.6            py39h6e9494a_0    conda-forge
numpy                     1.19.4           py39he588a01_2    conda-forge
olefile                   0.46               pyh9f0ad1d_1    conda-forge
openssl                   1.1.1i               h35c211d_0    conda-forge
packaging                 20.8               pyhd3deb0d_0    conda-forge
pandas                    1.2.0            py39h089d6f7_0    conda-forge
pandoc                    2.11.3.2             h35c211d_0    conda-forge
pandocfilters             1.4.3            py39hecd8cb5_1  
parso                     0.8.1              pyhd8ed1ab_0    conda-forge
patsy                     0.5.1                      py_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    8.1.0            py39hc06e9b5_0    conda-forge
pip                       20.3.3             pyhd8ed1ab_0    conda-forge
plotly                    4.14.1             pyhd3deb0d_0    conda-forge
prometheus_client         0.9.0              pyhd3deb0d_0    conda-forge
prompt-toolkit            3.0.8              pyha770c72_0    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pygments                  2.7.3              pyhd8ed1ab_0    conda-forge
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyrsistent                0.17.3           py39h5a22ff9_1    conda-forge
pysocks                   1.7.1            py39h2c36a5b_2    conda-forge
python                    3.9.1           h1d169a7_2_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.9                      1_cp39    conda-forge
pytz                      2020.5             pyhd8ed1ab_0    conda-forge
pyvis                     0.1.8.2            pyh9f0ad1d_0    conda-forge
pyzmq                     20.0.0           py39h07c395c_1    conda-forge
readline                  8.0                  h0678c8f_2    conda-forge
requests                  2.25.1             pyhd3deb0d_0    conda-forge
retrying                  1.3.3                      py_2    conda-forge
scipy                     1.6.0            py39hca3e1c3_0    conda-forge
seaborn                   0.11.1               h694c41f_0    conda-forge
seaborn-base              0.11.1             pyhd8ed1ab_0    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                51.0.0           py39hecd8cb5_2  
six                       1.15.0             pyh9f0ad1d_0    conda-forge
sniffio                   1.2.0            py39h6e9494a_0    conda-forge
sqlite                    3.34.0               h17101e1_0    conda-forge
statsmodels               0.12.1           py39hf24ec92_1    conda-forge
terminado                 0.9.1            py39h6e9494a_1    conda-forge
testpath                  0.4.4                      py_0    conda-forge
tk                        8.6.10               h0419947_1    conda-forge
tornado                   6.1              py39h5a22ff9_0    conda-forge
traitlets                 5.0.5                      py_0    conda-forge
tzdata                    2020f                he74cb21_0    conda-forge
urllib3                   1.26.2             pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
widgetsnbextension        3.5.1            py39h6e9494a_4    conda-forge
xz                        5.2.5                haf1e3a3_1    conda-forge
zeromq                    4.3.3                h74dc148_3    conda-forge
zipp                      3.4.0                      py_0    conda-forge
zlib                      1.2.11            h7795811_1010    conda-forge
zstd                      1.4.8                hf387650_1    conda-forge

Any help/ideas is extremely appreciated! Stackoverflow ticket: I am trying to open an HTML file using python - pyviz

Marchellemarcher answered 4/1, 2021 at 15:4 Comment(0)
M
7

Update: Turns out Pyvis (and IFrame) needs the HTML file and the Jupyter Notebook in the same folder for it to be shown correctly (otherwise the notebook throws the 404 error). So, by simply putting the HTML with the notebook in the same working directory, it all went well.

Marchellemarcher answered 4/1, 2021 at 20:24 Comment(0)
K
1

I saved file using net.save_graph("graphs.html")

Then running following code in cell worked for me

from IPython.display import display, HTML
  
# Read the contents of the HTML file
with open('<file path >', 'r') as file:
    html_content = file.read()
    
# Display the HTML content
display(HTML(html_content))
Kristin answered 24/6, 2023 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.