Skip to content

Commit

Permalink
Improve Kedro-viz experience on notebooks (kedro-org#1722)
Browse files Browse the repository at this point in the history
* Add link to open in new tab

* add test and lint

Signed-off-by: Sajid Alam <[email protected]>

* Update RELEASE.md

Signed-off-by: Sajid Alam <[email protected]>

---------

Signed-off-by: Sajid Alam <[email protected]>
Signed-off-by: Elias Santana <[email protected]>
  • Loading branch information
SajidAlamQB authored and santana98 committed Feb 19, 2024
1 parent 9b67bf1 commit 5604c9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
7 changes: 7 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Please follow the established format:
- Include the ID number for the related PR (or PRs) in parentheses
-->

# Upcoming release

## Major features and improvements
## Bug fixes and other changes
- Change the `%run_viz` line magic to open Kedro-viz in a new browser tab. (#1722)


# Release 7.1.0

## Major features and improvements
Expand Down
8 changes: 3 additions & 5 deletions package/kedro_viz/launchers/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def run_viz(port: int = None, local_ns: Dict[str, Any] = None) -> None:
if _is_databricks():
_display_databricks_html(port)
else:
wrapper = f"""
<html lang="en"><head></head><body style="width:100; height:100;">
<iframe src="http://{host}:{port}/" height=500 width="100%"></iframe>
</body></html>"""
display(HTML(wrapper))
url = f"http://{host}:{port}/"
link_html = f'<a href="{url}" target="_blank">Open Kedro-Viz</a>'
display(HTML(link_html))
16 changes: 16 additions & 0 deletions package/tests/test_launchers/test_jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ def test_run_viz_on_databricks(self, mocker, patched_check_viz_up, monkeypatch):
},
)
databricks_display.assert_called_once()

def test_run_viz_creates_correct_link(self, mocker, patched_check_viz_up):
mock_process_context = mocker.patch("multiprocessing.get_context")
mock_context_instance = mocker.Mock()
mock_process_context.return_value = mock_context_instance
mock_process = mocker.patch.object(mock_context_instance, "Process")
mock_display_html = mocker.patch("kedro_viz.launchers.jupyter.display")

run_viz()

mock_process.assert_called_once()
mock_display_html.assert_called_once()

displayed_html = mock_display_html.call_args[0][0].data
assert 'target="_blank"' in displayed_html
assert "Open Kedro-Viz" in displayed_html

0 comments on commit 5604c9d

Please sign in to comment.