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

Improve Kedro-viz experience on notebooks #1722

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
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
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