pythonpyvis

Disable pyvis from opening elinks by default


I work remotely on a Ubuntu system using a terminal and vi editor. I want to generate output using pyvis which I am able to do. However, running the code also creates a terrible side-effect of invoking a CLI browser (elinks) that keeps running in the background even if I exit at the beginning itself by pressing q. This becomes noticeable when I work with vi in escape mode and keeps showing the menu from which I cannot exit no matter what I try. Is there a way to stop this behavior? I tried the following:

from pyvis.network import Network
import networkx as nx
import os

g = nx.MultiGraph()

g.add_node(0, label='node 0', title='Node 1', shape='ellipse', size=125)
g.add_node(1, label='node 1', title='Node 2', shape='ellipse', size=125)
g.add_node(2, label='node 2', title='Node 3', shape='ellipse', size=125)

g.add_edge(0, 1, label='e1_1', title='e1_1',arrows="false")
g.add_edge(0, 1, label='e1_2', title='E1_2',arrows="false")
g.add_edge(0, 2, label='e2', title='E2',arrows="false")

nt = Network(directed=True)
nt.from_nx(g)
nt.set_edge_smooth('dynamic')
nt.show('foo.html', notebook=False)

nt.set_options('''
    var options = {
        "nodes": {
            "size": 100
        },
        "edges": {
            "arrowStrikethrough": false,
            "color": {
                "inherit": false
            },
            "font": {
                "size": 3,
                "align": "top"
            },
            "smooth": dynamic
        }
    }
''')

nt.show('foo.html', notebook=False)
os.system("xdg-open /dev/null foo.html")

I run it as the following:

$ python foo.py

Error on screen:

foo.html
xdg-open: unexpected argument 'foo.html'
Try 'xdg-open --help' for more information.
(base) eweb@genome:~/test$ cannot create temporary directory for the root file system: Permission denied
Warning: program returned non-zero exit code #256
Opening "foo.html" with Chromium Web Browser  (text/html)
cannot create temporary directory for the root file system: Permission denied
cannot create temporary directory for the root file system: Permission denied
/usr/bin/xdg-open: 882: firefox: not found
/usr/bin/xdg-open: 882: iceweasel: not found
/usr/bin/xdg-open: 882: seamonkey: not found
/usr/bin/xdg-open: 882: mozilla: not found
/usr/bin/xdg-open: 882: epiphany: not found
/usr/bin/xdg-open: 882: konqueror: not found
cannot create temporary directory for the root file system: Permission denied
cannot create temporary directory for the root file system: Permission denied
/usr/bin/xdg-open: 882: google-chrome: not found

Solution

  • If you don't want to open in browser then don't use os.system() and nt.show()
    but nt.write_html('foo.html')

    There is also generate_html() but I didn't test it.

    If you check source code show() then you see it also uses write_html()


    Doc: write_html(), generate_html()