pyvis icon indicating copy to clipboard operation
pyvis copied to clipboard

html not showing in `vscode` `jupyter` notebook

Open TheMcSquirrell opened this issue 2 years ago • 7 comments

I have the same issue that is posted by rickhg12hs on the vscode-jupyter page. I'm creating a simple graph via NetworkX, then trying to display it using pyvis. A blank space (of the given height) is the result:

image

If opened in my browser, the html file works fine:

image

TheMcSquirrell avatar Jan 04 '23 18:01 TheMcSquirrell

I had a similar issue when using pyvis on databricks.

The solution for me was to generate raw html and render that. So instead of your show command use:

from IPython.display import HTML
HTML(net.generate_html())

IvoMerchiers avatar Jan 05 '23 09:01 IvoMerchiers

I did try that, unfortunately that also doesn't work. It just creates an empty box and messes up my Jupyter notebook styling:

image

TheMcSquirrell avatar Jan 05 '23 10:01 TheMcSquirrell

Try

html = net.generate_html(notebook=True)
HTML(f'<div style="height:{net.height}">{html}</div>', metadata={"isolated": True}, )

I had the same problem, the CSS styling in the generated html is being applied to style the notebook. The isolated keyword fixes that. I also found that I needed to put the generated html in a div specifying the height of the rendered html, otherwise it rendered with 0 height.

pfebrer avatar Jan 08 '23 20:01 pfebrer

Thank you, but I'm afraid that still doesn't work for me. I get the exact same result as in my reaction to IvoMerchiers above.

TheMcSquirrell avatar Jan 09 '23 08:01 TheMcSquirrell

Hmm that's strange, it also messes up with the styling of the notebook? Perhaps the isolated keyword only works in jupyter notebooks...

pfebrer avatar Jan 09 '23 12:01 pfebrer

Try net=Network(notebook=True, cdn_resources='in_line') #specifically cdn_resources

There is a permission bug in chromium based browsers with jupyter notebook where they will not load resources from the local file system. From my observations it's because jupyter has a check on the headers of a request to ensure that who is attempting to grab the file is from jupyter in some way. Though middle of last year chrome started stripping those headers from

BerserkerGaruk avatar Jan 11 '23 23:01 BerserkerGaruk

cdn_resources doesn't work for me (or any of the HTML options.

david-waterworth avatar Nov 27 '23 21:11 david-waterworth