From b6a3d5cb48482d70056fa13274b0f05b91ca7a0c Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Mon, 20 Nov 2023 12:49:19 -0600 Subject: [PATCH] Handle altair's ConcatChart class more gracefully (#125) --- shinywidgets/_shinywidgets.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/shinywidgets/_shinywidgets.py b/shinywidgets/_shinywidgets.py index 8878391..6b69235 100644 --- a/shinywidgets/_shinywidgets.py +++ b/shinywidgets/_shinywidgets.py @@ -13,6 +13,7 @@ import json import os import tempfile +import warnings from typing import Any, Optional, Sequence, Tuple, Union, cast, overload from uuid import uuid4 from weakref import WeakSet @@ -334,11 +335,19 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]: # container since it'll be contained within the Layout() container, which has a # full-fledged sizing API. if pkg == "altair": - from altair import JupyterChart + import altair as alt # Since as_widget() has already happened, we only need to handle JupyterChart - if isinstance(widget, JupyterChart): - widget.chart = widget.chart.properties(width="container", height="container") # type: ignore + if isinstance(widget, alt.JupyterChart): + if isinstance(widget.chart, alt.ConcatChart): + # Throw warning to use ui.layout_column_wrap() instead + warnings.warn( + "Consider using shiny.ui.layout_column_wrap() instead of alt.concat() " + "for multi-column layout (the latter doesn't support filling layout)." + ) + else: + widget.chart = widget.chart.properties(width="container", height="container") # type: ignore + return (widget, fill)