Search code examples
pythonpyvis

I can't fix the mapping using pywis framework python


I ask for help. I use the pyvis framework to display the enterprise network. The network is drawn randomly, i have to use buttons to display it correctly. Is it possible to fix the button values in the python code so that the display is by default?

def openxslx (table_name, name_sheet = 'Sheet1'):
    x = pd.read_excel(f'{path_track}/{table_name}.xlsx', sheet_name= name_sheet)
    return x

def clear(hostname):
    hostname_re = re.sub("^\s+|\n|\r|\s+$", '', hostname)
    hostname_list = hostname_re.split(',')
    return hostname_list


oren = openxslx('XXXXX')
nx_graph = net.Network(width='75%', height= '700px', notebook = False, cdn_resources = 'local')

for i in range(oren.shape[0]):
    hostname_a = clear(oren['network_name(tchk_a)'][i]) 
    hostname_b = clear(oren['network_name(tchk_b)'][i])
    for hostname in hostname_a:
        for hostname1 in hostname_b:
            nx_graph.add_node(hostname, label=f'{hostname}', )
            nx_graph.add_node(hostname1, label=f'{hostname1}')
            nx_graph.add_edge(hostname, hostname1)





nx_graph.hrepulsion()
nx_graph.toggle_physics(False)
nx_graph.show_buttons(filter_=['layout'])
nx_graph.show('nx.html')
const options = {
  "layout": {
    "hierarchical": {
      "enabled": true,
      "levelSeparation": -85,
      "nodeSpacing": 225,
      "treeSpacing": 310,
      "direction": "DU",
      "sortMethod": "directed"
    }
  }
}

I tried to write the parameters in the string nx_graph = net.Network(width='75%', height= '700px', notebook = False, cdn_resources = 'local') returns an error


Solution

  • nx_graph.set_options(options=r'{"layout": {"hierarchical": {"enabled": true,"levelSeparation": -85,"nodeSpacing": 225,"treeSpacing": 310,"direction": "DU","sortMethod": "directed"}}}')