WestHealth / pyvis

Python package for creating and visualizing interactive network graphs.
http://pyvis.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
1.02k stars 174 forks source link

Alternative HTML Template #57

Open MogicianEik opened 4 years ago

MogicianEik commented 4 years ago

Hi developer team, can you allow users to specify their own HTML templates in visualization in future releases?

boludo00 commented 4 years ago

Hi! Yes, that is something I would want to implement going forward. Users should be able to specify path for their own templates. If you want this feature with current Pyvis, you could try replacing the templates/template.html in your site-packages pyvis installation, since by default it looks for the template there.

JonasCir commented 3 years ago

This is already possible by using Network.set_template and setting it to a custom template. write_html will then load the template from this path. The easy fix to make this more accessible would be to add path as an optional value to the constructor of Network I guess?


In this case write_html, has to take an additional (optional) **kwargs argument which then gets merged with the Jinja2 context that is already there. Otherwise, no new placeholders can be added to the custom template.

JonasCir commented 3 years ago

Also another thing that I noticed is that set_template does not set the template (jinja2.Template) but the path to the template

LeMoussel commented 3 years ago

This is already possible by using Network.set_template and setting it to a custom template. write_html will then load the template from this path.

Yep! I tested by doing this

pyvis_graph = Network(height="100%", width="100%")
pyvis_graph.set_template('template.html.j2')
# Do some stuff ....
pyvis_graph.write_html('test_template.html')
webbrowser.open('test_template.html')