Skip to content

Error to run the example #2

@SeqCrafter

Description

@SeqCrafter

My codes:

import reflex as rx
from reflex_altair import altair_chart
import altair as alt
import pandas as pd

chart_spec = (
        alt.Chart(alt.Data(name="dataset_id"))
        .mark_bar()
        .encode(x="category:O", y="value:Q", tooltip=["category", "value"])
        .properties(title="Bar Chart Example")
    )

class altairState(rx.State):
    
    chart_data: dict = {
        "dataset_id": pd.DataFrame(
            {"category": ["A", "B", "C"], "value": [28, 55, 43]}
        ).to_dict("records")
    }


@rx.page(route="/altair")
def altair_plots() -> rx.Component:
    return rx.container(
        rx.flex(
            rx.heading("test figure plots:"),
            altair_chart(
                spec=chart_spec,
                data=altairState.chart_data,
                actions=False,
                download_file_name="filename",
            ),
            width="100",
            direction="column",
        ),
        width="100%",
    )

error message:

TypeError: Unsupported type <class 'altair.vegalite.v5.api.Chart'> for LiteralVar. Tried to create a LiteralVar from alt.Chart(...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions