pyvis icon indicating copy to clipboard operation
pyvis copied to clipboard

Alternative HTML Template

Open MogicianEik opened this issue 5 years ago • 4 comments

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

MogicianEik avatar Feb 06 '20 20:02 MogicianEik

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.

boludo00 avatar Feb 06 '20 21:02 boludo00

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 avatar Dec 19 '20 18:12 JonasCir

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

JonasCir avatar Dec 19 '20 19:12 JonasCir

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')

LeMoussel avatar Mar 05 '21 09:03 LeMoussel