posit-dev / py-shinywidgets

Render ipywidgets inside a PyShiny app
MIT License
46 stars 5 forks source link

Altair chart size not respected #128

Closed adampinky85 closed 9 months ago

adampinky85 commented 9 months ago

Issue

We found an issue with Shiny rendering Altair charts where the size properties are not respected. These attributes work as expected when used in a Jupyter notebook but not within Shiny.

The Plotly equivalent attribute to set chart size works in Shiny without issue. There are also size attributes on the shinywidgets.output_widget method, which appear to work to increase the width but not height.

Minimal Example

import altair as alt
import shinywidgets
from shiny import ui, App
from vega_datasets import data

app_ui = ui.page_fluid(
    shinywidgets.output_widget("render_graph"),
)

def server(input, output, session):

    @shinywidgets.render_widget
    def render_graph():
        cars = data.cars()
        chart = (
            alt.Chart(cars)
            .mark_point()
            .encode(
                x="Horsepower",
                y="Miles_per_Gallon",
                color="Origin",
            )
            .properties(width=500, height=2_000)
        )
        return chart

app = App(app_ui, server)

Versions

cpsievert commented 9 months ago

Thanks!

adampinky85 commented 9 months ago

thanks @cpsievert, much appreciated! Do you know when this PR will be released in a new version?

cpsievert commented 9 months ago

Hopefully next week