Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st.line_chart don't work in stlite/desktop #656

Closed
CMajorChords opened this issue Nov 30, 2023 · 5 comments
Closed

st.line_chart don't work in stlite/desktop #656

CMajorChords opened this issue Nov 30, 2023 · 5 comments

Comments

@CMajorChords
Copy link

This issue seems to be caused by the Altair package updating its dependency on pyarrow, which was not the case before. It seems that pyarrow cannot be installed on pyodide. The error is as follows:

RuntimeError: The pyarrow package must be version 11.0.0 or greater. Found version 0.0.1
Traceback:
File "streamlit/runtime/scriptrunner/script_runner.py", line 557, in _run_script
File "/home/pyodide/pages/1产流机制分析.py", line 44, in <module>
    产流机制分析.计算年最大流量(RunoffData)
File "/home/pyodide/modules/产流机制分析.py", line 90, in 计算年最大流量
    st.line_chart(annualMaxRunoff)
File "streamlit/runtime/metrics_util.py", line 356, in wrapped_func
File "streamlit/elements/dataframe_selector.py", line 301, in line_chart
File "streamlit/runtime/metrics_util.py", line 356, in wrapped_func
File "streamlit/elements/arrow_altair.py", line 131, in _arrow_line_chart
File "streamlit/elements/arrow_altair.py", line 610, in marshall
File "/lib/python3.11/site-packages/altair/vegalite/v5/api.py", line 2975, in to_dict
    return super().to_dict(
           ^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/vegalite/v5/api.py", line 961, in to_dict
    vegalite_spec = super(TopLevelMixin, copy).to_dict(  # type: ignore[misc]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 961, in to_dict
    result = _todict(
             ^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 477, in _todict
    return {k: _todict(v, context) for k, v in obj.items() if v is not Undefined}
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 477, in <dictcomp>
    return {k: _todict(v, context) for k, v in obj.items() if v is not Undefined}
               ^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 473, in _todict
    return obj.to_dict(validate=False, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 961, in to_dict
    result = _todict(
             ^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 477, in _todict
    return {k: _todict(v, context) for k, v in obj.items() if v is not Undefined}
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 477, in <dictcomp>
    return {k: _todict(v, context) for k, v in obj.items() if v is not Undefined}
               ^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/schemapi.py", line 473, in _todict
    return obj.to_dict(validate=False, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/vegalite/v5/schema/channels.py", line 54, in to_dict
    parsed = parse_shorthand(shorthand, data=context.get("data", None))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/core.py", line 586, in parse_shorthand
    if pyarrow_available() and data is not None and hasattr(data, "__dataframe__"):
       ^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/altair/utils/_importers.py", line 90, in pyarrow_available
    import_pyarrow_interchange()
File "/lib/python3.11/site-packages/altair/utils/_importers.py", line 69, in import_pyarrow_interchange
    raise RuntimeError(

Altair updated to version 5.2.0 a few days ago, and I am unable to specify the Altair version via requirements. txt. It seems that the latest version was already installed when installing the streamlit dependency.

@andeplane
Copy link
Contributor

andeplane commented Dec 8, 2023

Seems like pyarrow>=11 has been a dependency in altair since this PR June 7th. Streamlit depending on altair versions after that won't work since we mock pyarrow.

@andeplane
Copy link
Contributor

andeplane commented Dec 8, 2023

@lukasmasuch any ideas how we can deal with this in stlite? We may have to wait for pyarrow support in pyodide which seems to have had ok progress over the past months.

@whitphx
Copy link
Owner

whitphx commented Dec 26, 2023

This should be fixed with a new release, 0.42.4.
It pins the altair version to <5.2.0 as a workaround.

Plz wait more for a long-term solution fixing the pyarrow mock versioning and allowing altair>=5.2.0 to be installed.

@lukasmasuch
Copy link
Contributor

I added this monkey patching to bootstrap.py in my local stlite version:

def _fix_altair():
    """Fix an issue with Altair and the mocked pyarrow module of stlite."""
    try:
        from altair.utils import _importers

        def _pyarrow_available():
            return False

        _importers.pyarrow_available = _pyarrow_available

        def _import_pyarrow_interchange():
            raise ImportError("Pyarrow is not available in stlite.")

        _importers.import_pyarrow_interchange = _import_pyarrow_interchange
    except:
        pass

But I think a better solution might be that this import import pyarrow.interchange as pi from the pyarrow mock package produces an import arrow so that altair is not trying to use the interchange protocol:

https://github.com/altair-viz/altair/blob/b0812372cd1b33c2bd3a330b3c4749080feefba8/altair/utils/_importers.py#L76

@whitphx
Copy link
Owner

whitphx commented Feb 6, 2024

This should be fixed in the latest version.

@whitphx whitphx closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants