Open yutxie opened 3 years ago
I am having the same problem. In the following code, the OPTIONS were copied from Generate Options output. Yet as you can see the hierarchical option (among others) do not "take).
edges = [
('1', '1.1'),
('1', '1.2'),
('1.2', '1.2.1'),
('1.2', '1.2.2'),
('2', '2.1')
]
OPTIONS = """{
"edges": {
"color": {
"inherit": true
},
"smooth": false
},
"layout": {
"hierarchical": {
"enabled": true
}
},
"physics": {
"hierarchicalRepulsion": {
"centralGravity": 0
},
"minVelocity": 0.75,
"solver": "hierarchicalRepulsion"
}
}"""
g=net.Network(notebook=True)
g.options.set(OPTIONS) ##This is not working
names=[]
for parent, name in edges:
g.add_node(parent,shape='box')
g.add_node(name, shape='box')
print(name)
if parent:
g.add_edge(parent, name)
print(f"('{parent}', '{name}'),")
g.show_buttons()
g.show('fromraw.html')
Hi guys, I have been playing around with this as of visjs version 9.0.4 and it is giving me really buggy results. So I am not for certain what could be the issue, I am thinking something in the JS layer as there are several errors thrown in the browser debugger when making UI changes.
Has anyone found a solution for this? I'm running into an AttributeError: 'dict' object has no attribute 'configure'
when I try and pass JSON options in the same format as OP.
Hi, I think this is because when you use Network.show_buttons(), then if you check webpage source then you can see a framework adds this key 'configure' to json, which is not suggested when you copy it from the GUI:
var options = {
"configure": {
"enabled": true
},
"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
}
}
};
So the workaround is to always include this section in e.g.
options = """
var options = {
"configure": {
"enabled": true
},
"edges": {
"color": {
"inherit": true
},
"smooth": false
},
"physics": {
"barnesHut": {
"gravitationalConstant": -12050
},
"minVelocity": 0.75
}
}
"""
net.set_options(options)
But I think this is an issue, either this should be managed by Pyvis already.
@Marcin-Radecki Can you put together a pull request for this? I just merged a bunch of them.
This is still an issue - if you add the "configure" statement, it renders fine, but then showbuttons(filter=['physics']) throws an error - AttributeError: 'dict' object has no attribute 'configure' So I think that show_buttons is constructing a version of the dict without the configure and that's what's causing the problem. Here's a quick vid of the issue. Let me know if you can't get to it - I can move it to a personal account, rather than a company one.
Having the same problem, no "configure" object is recreated in set_options
yeah -- I also had to include my filters in the "configure" key -- otherwise was getting that "AttributeError: 'dict' object has no attribute 'configure'"
options = '''
var options = {
"configure": {
"enabled": true,
"filter": ["physics"]
},
#other content from the "generate options" output
...
'''
net.set_options(options)
net.write_html(file)
I can confirm this is a good workaround for me.
yeah -- I also had to include my filters in the "configure" key -- otherwise was getting that "AttributeError: 'dict' object has no attribute 'configure'"
options = ''' var options = { "configure": { "enabled": true, "filter": ["physics"] }, #other content from the "generate options" output ... ''' net.set_options(options) net.write_html(file)
@.*** cell: 585-738-6696 Co-Founder, e-NABLE: volunteers worldwide making free, 3D printed prosthetics Innovation Fellow, JMK Innovation Fund
Sent from iPhone: beware tyops.
On Fri, Dec 8, 2023 at 9:33 AM Dr. Jorge Abreu Vicente < @.***> wrote:
I can confirm this is a good workaround for me.
yeah -- I also had to include my filters in the "configure" key -- otherwise was getting that "AttributeError: 'dict' object has no attribute 'configure'"
options = '''var options = { "configure": { "enabled": true, "filter": ["physics"] },#other content from the "generate options" output...'''net.set_options(options)net.write_html(file)
— Reply to this email directly, view it on GitHub https://github.com/WestHealth/pyvis/issues/81#issuecomment-1846854891, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAANDKMKLGKJU2W4GORKK53YILNF5AVCNFSM4W4Y7O4KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBUGY4DKNBYHEYQ . You are receiving this because you commented.Message ID: @.***>
In the source code listed in the documentation generate_html, it shows that the option physics has a sub-key enabled.
In the Network constructor, add this dictionary to physics:
Network(options={"physics": {"enabled": False}})
In the source code listed in the documentation generate_html, it shows that the option physics has a sub-key enabled.
In the Network constructor, add this dictionary to physics:
Network(options={"physics": {"enabled": False}})
Hmm
newgraph = Network('800px', width="100%", cdn_resources="local", options={"layout": {"hierarchical": {"direction": "UD"}}})
TypeError: Network.__init__() got an unexpected keyword argument 'options'
Getting the same issue in July 2024? Any fix?
Hi! I'm trying to use the
set_options(...)
function to set default configurations. However, the visualization fails to be loaded after this function is called.Below is my testing code.
I have also tried to remove the
set_options(...)
part as below, and found the desired figure can be shown immediately afternet.show("ex.html")
.I printed out the default
net.options
. It goes like this:I was wondering whether some essential elements (e.g., pyvis.physics.Physics.Stabilization object) were lost during modifying
net.options
, so that the figure could not be loaded as expected.Hope you could help me with this! Thank you so much!