posit-dev / py-shinywidgets

Render ipywidgets inside a PyShiny app
MIT License
41 stars 2 forks source link

Altair Facetchart rendering issue #142

Closed dreamtori closed 3 months ago

dreamtori commented 3 months ago

Description

Hi team,

When we generate a facet chart, an error occurs while rendering the altair facet chart.

error message Facetchart object has no attribute 'width'

I'd really appreciate your help. many thanks!

What I Did

minimal example

from shiny.express import input, ui
from shinywidgets import render_altair

ui.input_selectize("var", "Select variable", choices=["bill_length_mm", "body_mass_g"])

@render_altair
def hist():
    import altair as alt
    from palmerpenguins import load_penguins

    df = load_penguins()
    return (
        alt.Chart(df)
        .mark_bar()
        .encode(x=alt.X(f"{input.var()}:Q", bin=True), y="count()")
    ).facet(column='species:N')
cpsievert commented 3 months ago

Thanks! I was quite surprised to learn that vega doesn't support specifying height/width on a FacetChart, so the sizing will be awkward/non-responsive, but @render_altair won't error on it anymore.