Skip to content

Commit 5604c9d

Browse files
SajidAlamQBsantana98
authored andcommitted
Improve Kedro-viz experience on notebooks (kedro-org#1722)
* Add link to open in new tab * add test and lint Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> * Update RELEASE.md Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> --------- Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com> Signed-off-by: Elias Santana <eliasvssantana@gmail.com>
1 parent 9b67bf1 commit 5604c9d

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

RELEASE.md

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Please follow the established format:
66
- Include the ID number for the related PR (or PRs) in parentheses
77
-->
88

9+
# Upcoming release
10+
11+
## Major features and improvements
12+
## Bug fixes and other changes
13+
- Change the `%run_viz` line magic to open Kedro-viz in a new browser tab. (#1722)
14+
15+
916
# Release 7.1.0
1017

1118
## Major features and improvements

package/kedro_viz/launchers/jupyter.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ def run_viz(port: int = None, local_ns: Dict[str, Any] = None) -> None:
122122
if _is_databricks():
123123
_display_databricks_html(port)
124124
else:
125-
wrapper = f"""
126-
<html lang="en"><head></head><body style="width:100; height:100;">
127-
<iframe src="http://{host}:{port}/" height=500 width="100%"></iframe>
128-
</body></html>"""
129-
display(HTML(wrapper))
125+
url = f"http://{host}:{port}/"
126+
link_html = f'<a href="{url}" target="_blank">Open Kedro-Viz</a>'
127+
display(HTML(link_html))

package/tests/test_launchers/test_jupyter.py

+16
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,19 @@ def test_run_viz_on_databricks(self, mocker, patched_check_viz_up, monkeypatch):
8888
},
8989
)
9090
databricks_display.assert_called_once()
91+
92+
def test_run_viz_creates_correct_link(self, mocker, patched_check_viz_up):
93+
mock_process_context = mocker.patch("multiprocessing.get_context")
94+
mock_context_instance = mocker.Mock()
95+
mock_process_context.return_value = mock_context_instance
96+
mock_process = mocker.patch.object(mock_context_instance, "Process")
97+
mock_display_html = mocker.patch("kedro_viz.launchers.jupyter.display")
98+
99+
run_viz()
100+
101+
mock_process.assert_called_once()
102+
mock_display_html.assert_called_once()
103+
104+
displayed_html = mock_display_html.call_args[0][0].data
105+
assert 'target="_blank"' in displayed_html
106+
assert "Open Kedro-Viz" in displayed_html

0 commit comments

Comments
 (0)