Skip to content

Commit 58ccda3

Browse files
Change output to not use widget when just running as HTML
1 parent 270a187 commit 58ccda3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

python/egglog/visualizer_widget.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import anywidget
55
import traitlets
66
from IPython.display import display
7-
from ipywidgets.embed import embed_minimal_html
87

8+
# from ipywidgets.embed import embed_minimal_html
99
from .ipython_magic import IN_IPYTHON
1010

1111
CURRENT_DIR = pathlib.Path(__file__).parent
@@ -33,7 +33,21 @@ def display_or_open(self) -> None:
3333
# 2. Write the widget to it with embed_minimal_html
3434
# 3. Open the file using the open function from graphviz
3535
file = pathlib.Path.cwd() / "tmp.html"
36+
file.write_text(HTML.replace("MAGIC_STRING", str(self.egraphs)))
3637
# https://github.com/manzt/anywidget/issues/339#issuecomment-1755654547
37-
embed_minimal_html(file, views=[self], drop_defaults=False)
38+
# embed_minimal_html(file, views=[self], drop_defaults=False)
39+
# Instead of embedding widget, just save
3840
print("Visualizer widget saved to", file)
3941
webbrowser.open(file.as_uri())
42+
43+
44+
HTML = """
45+
<div id="egraph-visualizer"></div>
46+
<link rel="stylesheet" href="https://esm.sh/egraph-visualizer/dist/style.css" />
47+
<script type="module">
48+
import { mount } from "https://esm.sh/egraph-visualizer";
49+
const egraphs = MAGIC_STRING;
50+
const mounted = mount(document.getElementById("egraph-visualizer"));
51+
mounted.render(egraphs);
52+
</script>
53+
"""

0 commit comments

Comments
 (0)