Comments (6)
Found the answer... pretty clever library, the options are dictionaries mirroring the JS code.
import pandas as pd
net = Network(height="400px", width="400px", bgcolor="#222222", font_color="white", notebook=True, directed=True)
net.options.groups = {
"users": {
"shape": 'icon',
"icon": {
"face": 'FontAwesome',
"code": '\uf0c0',
"size": 50,
"color": 'orange'
}
},
"table": {
"shape": 'icon',
"icon": {
"face": 'FontAwesome',
"code": '\uf0ce',
"size": 50,
"color": 'green'
}
}
}
net.add_node("a", shape="icon", group="users")
net.add_node("b", shape="icon", group="table")
net.add_edge("a","b")
net.show("net.html")
# patch in font-awesome css
# replace https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css
html_str = net.html.replace(
'<head>',
'<head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css"/>'
)
#print(html_str)
displayHTML(html_str)```
from pyvis.
from pyvis.
The answer lies in https://pyvis.readthedocs.io/en/latest/documentation.html#pyvis.network.Network.add_node and the 'group' optional parameter to the node.
from pyvis.
Please note I still have to hack in the font-awesome CSS...
# replace https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css
html_str = net.html.replace(
'<head>',
'<head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css"/>'
)```
from pyvis.
Elegant solution. I spent the evening trying to figure this out.
from pyvis.
Answered: #53 (comment)
Closing, but might add an example using this method.
from pyvis.
Related Issues (20)
- Pyvis HTML Output does not use 100% of the page HOT 2
- Save as json
- Problem with labels, trying integration with pandas, Latex and Networkx
- No display of node labels if node is numeric HOT 1
- Change node size when label is inside
- Numeric string node ID silently cast from `str` to `int` in in `add_nodes` but not `add_edges`, raises `AssertionError`
- `write_html` opens browser to relative rather than absolute path, doesn't handle absolute paths as name
- Network not handling objects: assert isinstance(n_id, str) or isinstance(n_id, int) HOT 1
- Customizing Filter Menu Attribute Names in pyvis
- Loading Bar Toggle
- ModuleNotFoundError: No module named 'pyvis.network'; 'pyvis' is not a package
- pyvis node labels don't appear sometimes
- Applying physics to individual edges or applying different physics to each edge
- Color picker is broken (from Network.show_buttons())
- Network.set_options node color is broken. HOT 2
- Network.show_buttons() and network.set_options() behave unexpectedly when ran on the same network. HOT 1
- Edge filter doesn't work with multiple edges
- Spread out Nodes in hierarchal format
- tooltip_link enable for custom data.
- [ERROR] OSError: [Errno 30] Read-only file system: 'lib'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvis.