Skip to content

Commit 37a68aa

Browse files
committed
Datalore/Colab: make LetsPlot.setup_html() only mandatory for Jupyter notebooks.
1 parent d3cd0d9 commit 37a68aa

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

python-package/lets_plot/frontend_context/_configuration.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Dict, Any
66

77
from ._frontend_ctx import FrontendContext
8-
from ._html_contexts import _create_html_frontend_context
8+
from ._html_contexts import _create_html_frontend_context, _use_isolated_frame
99
from .._global_settings import _get_global_bool
1010
from ..plot.core import PlotSpec
1111
from ..plot.plot import GGBunch
@@ -84,14 +84,20 @@ def _display_plot(plot_spec: Any):
8484

8585
def _as_html(plot_spec: Dict) -> str:
8686
"""
87+
Creates plot HTML using 'html' frontend context.
88+
8789
:param plot_spec: dict
8890
"""
8991
if 'html' not in _frontend_contexts:
90-
return """\
91-
<div style="color:darkred;">
92-
Lets-plot `html` is not configured.<br>
93-
Try to use `LetsPlot.setup_html()` before first occurrence of plot.
94-
</div>
95-
"""
92+
if _use_isolated_frame():
93+
# 'Isolated' HTML context can be setup lazily.
94+
_setup_html_context(isolated_frame=True, offline=False)
95+
else:
96+
return """\
97+
<div style="color:darkred;">
98+
Lets-plot `html` is not configured.<br>
99+
Try to use `LetsPlot.setup_html()` before first occurrence of plot.
100+
</div>
101+
"""
96102

97103
return _frontend_contexts['html'].as_str(plot_spec)

python-package/lets_plot/frontend_context/_html_contexts.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ def _create_html_frontend_context(isolated_frame: bool = None, offline: bool = N
1616
:return:
1717
"""
1818
if isolated_frame is None:
19-
# ToDo: check env var first
20-
21-
isolated_frame = _detect_isolated_frame()
19+
isolated_frame = _use_isolated_frame()
2220

2321
if isolated_frame:
2422
return StaticHtmlPageContext(offline)
2523
else:
2624
return JupyterNotebookContext(offline)
2725

2826

27+
def _use_isolated_frame() -> bool:
28+
# ToDo: check env var first
29+
30+
return _detect_isolated_frame()
31+
32+
2933
def _detect_isolated_frame() -> bool:
3034
if not _is_IPython_display():
3135
return True # isolated HTML page to show somehow

0 commit comments

Comments
 (0)