Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing .show: adding support for call without "name" support for no file saving #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def save_graph(self, name):
check_html(name)
self.write_html(name)

def generate_html(self, name="index.html", local=True, notebook=False):
def generate_html(self, name="index.html", notebook=False):
"""
This method gets the data structures supporting the nodes, edges,
and options and updates the template to write the HTML holding
Expand Down Expand Up @@ -497,7 +497,7 @@ def generate_html(self, name="index.html", local=True, notebook=False):
)
return self.html

def write_html(self, name, local=True, notebook=False,open_browser=False):
def write_html(self, name, notebook=False, open_browser=False):
"""
This method gets the data structures supporting the nodes, edges,
and options and updates the template to write the HTML holding
Expand Down Expand Up @@ -530,22 +530,26 @@ def write_html(self, name, local=True, notebook=False,open_browser=False):
out.write(self.html)
else:
assert "cdn_resources is not in ['in_line','remote','local']."
if open_browser: # open the saved file in a new browser window.
if open_browser: # open the saved file in a new browser window.
webbrowser.open(getcwd_name)


def show(self, name, local=True,notebook=True):
def show(self, name=None, notebook=True, string=False):
"""
Writes a static HTML file and saves it locally before opening.

:param: name: the name of the html file to save as
:param: notebook: if true, return an object displayable in a notebook
:param: string: return the html as a string instead
:type name: str
:type notebook: bool
:type string: bool
"""
if string:
return self.generate_html(notebook=notebook)

print(name)
if notebook:
self.write_html(name, open_browser=False,notebook=True)
else:
self.write_html(name, open_browser=True)
name = name or tempfile.mkdtemp() + "/index.hml"
self.write_html(name, open_browser=False, notebook=notebook)
if notebook:
return IFrame(name, width=self.width, height=self.height)

Expand Down