Skip to content

Support Altair charts #7

@joelostblom

Description

@joelostblom

Is your feature request related to a problem? Please describe.

Currently, altair charts renders as text:

image

The output from altair is vega-lite specs that can be rendered as interactive HTML. I tried some of the different renderers here https://altair-viz.github.io/user_guide/display_frontends.html, such as PNG and SVG, but none of them display.

Describe the solution you'd like
Chart objects to render by default as they do in a notebook environment.

Describe alternatives you've considered
Not sure what an alternative solution would be here.

Additional context

Code:

import pyodide_js
await pyodide_js.loadPackage('micropip')
import micropip
await micropip.install('altair')

import altair as alt
import pandas as pd

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

chart = alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)

chart

Edit: Modified the MWE to include await before micropip.install().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions