Skip to content

Commit

Permalink
Get altair's properties() method working again (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert authored Jan 17, 2024
1 parent 4451359 commit 5402282
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [UNRELEASED]

* The `@render_widget` decorator now attaches a `widget` (and `value`) attribute to the function it decorates. This allows for easier access to the widget instance (or value), and eliminates the need for `register_widget` (which is now soft deprecated). (#119)
* The `.properties()` method on `altair.Chart` object now works as expected again. (#129)
* Reduce default plot margins on plotly graphs.

## [0.2.4] - 2023-11-20
Expand Down
16 changes: 10 additions & 6 deletions shinywidgets/_render_widget_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,20 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]:

# Since as_widget() has already happened, we only need to handle JupyterChart
if isinstance(widget, alt.JupyterChart):
if isinstance(
widget.chart, # pyright: ignore[reportUnknownMemberType]
alt.ConcatChart,
):
chart = cast(alt.JupyterChart, widget).chart # type: ignore
if isinstance(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)."
"for multi-column layout (the latter doesn't support filling layout).",
stacklevel=2
)
else:
widget.chart = widget.chart.properties(width="container", height="container") # type: ignore
UndefinedType = alt.utils.schemapi.UndefinedType # type: ignore
if isinstance(chart.width, UndefinedType): # type: ignore[reportMissingTypeStubs]
chart = chart.properties(width="container") # type: ignore
if isinstance(chart.height, UndefinedType): # type: ignore[reportMissingTypeStubs]
chart = chart.properties(height="container") # type: ignore
widget.chart = chart

return (widget, fill)

0 comments on commit 5402282

Please sign in to comment.