I am creating a GUI element to visualize graphs generated using PyVis. PyVis outputs the graphs into an html file. You can open this file in a browser to see a fully interactive graph which looks like this.
The problem is that I'm now trying to embed this into a greater GUI design and when I try opening the html file in wxpython or tkinter (I have tried both), it ends up coming up as blank like so.
Here is the simple test code that I am using to produce this. I got this code from this other question:
import wx
import wx.html2
class MyBrowser(wx.Dialog):
def __init__(self, *args, **kwds):
wx.Dialog.__init__(self, *args, **kwds)
sizer = wx.BoxSizer(wx.VERTICAL)
self.browser = wx.html2.WebView.New(self)
sizer.Add(self.browser, 1, wx.EXPAND, 10)
self.SetSizer(sizer)
self.SetSize((700, 700))
if __name__ == '__main__':
app = wx.App()
dialog = MyBrowser(None, -1)
dialog.browser.LoadURL("file:///C:/Users/GARcher/PycharmProjects/PROJECT/saved.html")
dialog.Show()
app.MainLoop()
The html file which I am trying to open is as follows:
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis.css" type="text/css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis-network.min.js"> </script>
<center>
<h1></h1>
</center>
<!-- <link rel="stylesheet" href="../node_modules/vis/dist/vis.min.css" type="text/css" />
<script type="text/javascript" src="../node_modules/vis/dist/vis.js"> </script>-->
<style type="text/css">
#mynetwork {
width: 500px;
height: 500px;
background-color: #ffffff;
border: 1px solid lightgray;
position: relative;
float: left;
}
</style>
</head>
<body>
<div id = "mynetwork"></div>
<script type="text/javascript">
// initialize global variables.
var edges;
var nodes;
var network;
var container;
var options, data;
// This method is responsible for drawing the graph, returns the drawn network
function drawGraph() {
var container = document.getElementById('mynetwork');
// parsing and collecting nodes and edges from the python
nodes = new vis.DataSet([{"id": 1, "label": "192.168.0.121", "shape": "dot"}, {"id": 2, "label": "192.168.0.64", "shape": "dot"}, {"id": 3, "label": "192.168.0.101", "shape": "dot"}, {"id": 4, "label": "192.168.0.22", "shape": "dot"}, {"id": 5, "label": "192.168.0.69", "shape": "dot"}, {"id": 6, "label": "ROUTER", "shape": "dot"}]);
edges = new vis.DataSet([{"from": 1, "to": 6}, {"from": 2, "to": 6}, {"from": 3, "to": 6}, {"from": 4, "to": 6}, {"from": 5, "to": 6}, {"from": 1, "to": 2}, {"from": 3, "to": 4}, {"from": 4, "to": 5}]);
// adding nodes and edges to the graph
data = {nodes: nodes, edges: edges};
var options = {
"configure": {
"enabled": false
},
"edges": {
"color": {
"inherit": true
},
"smooth": {
"enabled": false,
"type": "continuous"
}
},
"interaction": {
"dragNodes": true,
"hideEdgesOnDrag": false,
"hideNodesOnDrag": false
},
"physics": {
"enabled": true,
"stabilization": {
"enabled": true,
"fit": true,
"iterations": 1000,
"onlyDynamicEdges": false,
"updateInterval": 50
}
}
};
network = new vis.Network(container, data, options);
return network;
}
drawGraph();
</script>
</body>
</html>
Anyway, my question is why is this not working in wxPython or tkinter and how can I resolve this issue? Any help would be greatly appreciated!