vega / altair

Declarative visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.41k stars 795 forks source link

Javascript Error: Failed to execute 'setAttribute' on 'Element': '0' #3041

Closed partus closed 1 year ago

partus commented 1 year ago

image the issue is available with altair==5.0.0rc3 . works fine with version 4.2.2

The snippet is executed in jupyter lab jupyter lab --version 3.6.3

mattijn commented 1 year ago

Thanks for reporting! The specification in your issue is a copy from https://altair-viz.github.io/gallery/scatter_matrix.html.

This works fine on the website and for me locally. I have not been able to reproduce this error yet. I will try a bit more.

Meanwhile, I have a few questions that can help me in reproducing the error you describe.

  1. Did you install altair from within a notebook cell or from the command prompt?
  2. If you installed it by command prompt, did you install altair before you start a jupyter-lab session or did you install it during a jupyter-lab session?

Last question:

  1. Is this error reoccurring after you close the current jupyter-lab session and restart jupyter-lab again?
partus commented 1 year ago

Thank you for the quick response. I had upgraded everything on the system in between. including python version and all possible packages and the issue is gone . Now it works and I cannot reproduce it either. According to the actions that I have taken, It might be a result of some very weak version dependency. Closing the issue as neither of us can reproduce it :D

JanetMatsen commented 1 year ago

I am having the same issue, but in a complex environment that won't make it easy to reproduce. I did pip install Altair in a Sagemaker Studio environment (which I haven't restarted since). Here is my pip freeze results, for what it's worth:

altair==5.0.0
argon2-cffi==21.1.0
asttokens==2.2.1
attrs==20.3.0
backcall==0.2.0
beautifulsoup4==4.11.1
black==23.3.0
bleach==4.1.0
blinker==1.6.2
boto3==1.26.120
boto3-stubs==1.26.119
botocore==1.29.120
botocore-stubs==1.29.119
bytecode==0.14.1
catboost==1.1.1
category-encoders==2.2.2
cattrs==1.8.0
certifi==2022.12.7
cffi==1.14.6
charset-normalizer==2.0.7
click==8.1.3
cloudpickle==2.0.0
colorama==0.4.4
comm==0.1.3
convertdate==2.4.0
cryptography==40.0.2
cycler==0.10.0
Cython==0.29.17
dask==2023.4.1
datadog==0.45.0
ddsketch==2.0.4
ddtrace==1.12.1
debugpy==1.5.0
decopatch==1.4.10
decorator==4.4.2
defusedxml==0.7.1
Deprecated==1.2.13
distributed==2023.4.1
entrypoints==0.3
envier==0.4.0
evalml==0.74.0
executing==1.2.0
featuretools==1.25.0
featuretools-tsfresh-primitives==1.0.1
Flask==2.2.4
fsspec==2021.10.0
graphviz==0.17
greenlet==2.0.2
gunicorn==20.1.0
hijri-converter==2.2.4
holidays==0.16
hypothesis==6.23.2
idna==3.2
imageio==2.11.1
imbalanced-learn==0.9.1
importlib-metadata==6.0.1
importlib-resources==5.10.2
iniconfig==1.1.1
ipykernel==6.4.1
ipython==7.32.0
ipython-genutils==0.2.0
ipywidgets==7.6.5
itsdangerous==2.1.2
jedi==0.18.0
Jinja2==3.1.2
jmespath==0.10.0
joblib==1.2.0
jsonschema==4.1.0
jupyter-client==7.0.6
jupyter_core==5.1.0
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.2
kaleido==0.2.1
kiwisolver==1.3.2
korean-lunar-calendar==0.3.1
lightgbm==3.3.3
lime==0.2.0.1
llvmlite==0.39.1
locket==1.0.0
lxml==4.9.1
makefun==1.12.1
MarkupSafe==2.1.1
matplotlib==3.4.3
matplotlib-inline==0.1.3
matrixprofile==1.1.10
mistune==2.0.4
msgpack==1.0.2
mypy-boto3-kms==1.26.81
mypy-boto3-secretsmanager==1.26.116
mypy-boto3-ssm==1.26.97
mypy-extensions==1.0.0
nbclient==0.5.4
nbconvert==7.0.0
nbformat==5.1.3
nest-asyncio==1.5.1
networkx==3.1
nlp-primitives==2.10.0
nltk==3.7
notebook==6.4.12
numba==0.56.4
numpy==1.21.6
opentelemetry-api==1.17.0
packaging==23.1
pandas==1.5.3
pandocfilters==1.5.0
parso==0.8.2
partd==1.2.0
pathspec==0.11.1
patsy==0.5.2
pep517==0.12.0
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.3.0
pip-tools==6.6.2
platformdirs==2.5.4
plotly==5.3.1
pluggy==1.0.0
pmdarima==1.8.5
prometheus-client==0.11.0
prompt-toolkit==3.0.20
protobuf==3.11.2
psutil==5.8.0
psycopg2==2.9.3
ptyprocess==0.7.0
pure-eval==0.2.2
py==1.11.0
pyaml==21.10.1
pycparser==2.20
pydantic==1.10.7
Pygments==2.10.0
PyJWT==2.6.0
PyMeeus==0.5.11
pyparsing==2.4.7
pyrsistent==0.18.0
pytest==7.1.2
pytest-cases==3.6.13
pytest-mock==3.8.1
python-dateutil==2.8.2
python-dotenv==1.0.0
pytz==2021.3
PyWavelets==1.2.0
PyYAML==5.4.1
pyzmq==22.3.0
regex==2021.10.8
requests==2.26.0
s3fs==0.4.0
s3transfer==0.6.0
sagemaker-experiments==0.1.39
scikit-image==0.18.3
scikit-learn==1.2.2
scikit-optimize==0.9.0
scipy==1.7.1
seaborn==0.11.2
Send2Trash==1.8.0
sentry-sdk==1.21.0
shap==0.40.0
six==1.16.0
sktime==0.17.0
slicer==0.0.7
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
SQLAlchemy==2.0.3
stack-data==0.6.2
statsmodels==0.12.2
structlog==22.3.0
structlog-sentry==2.0.2
stumpy==1.9.2
tabulate==0.9.0
tblib==1.7.0
tenacity==8.0.1
terminado==0.12.1
texttable==1.6.4
threadpoolctl==3.0.0
tifffile==2021.11.2
tinycss2==1.1.1
tokenize-rt==5.0.0
tomli==2.0.1
toolz==0.11.1
tornado==6.1
tqdm==4.62.3
traitlets==5.6.0
tsfresh==0.18.0
types-awscrt==0.16.16
types-s3transfer==0.6.0.post7
typing_extensions==4.4.0
urllib3==1.26.15
vowpalwabbit==8.11.0
wcwidth==0.2.5
webencodings==0.5.1
Werkzeug==2.3.3
widgetsnbextension==3.5.1
woodwork==0.23.0
wrapt==1.14.1
xgboost==1.7.2
xmltodict==0.13.0
zict==3.0.0
zipp==3.8.1
mattijn commented 1 year ago

Thanks for re-raising @JanetMatsen. I see your pip freeze shows that you are on altair version 5.0.0 and jsonschema version 4.1.0.

Are these versions also reported if you run the following code just before the place where this error occurs?

import importlib.metadata
importlib.metadata.version("jsonschema"), importlib.metadata.version("altair")
JanetMatsen commented 1 year ago

Yes:

('4.1.0', '5.0.0')

Thank you for looking into this!

mattijn commented 1 year ago

I can reproduce it in jupyter-notebook (even with jsonschema 4.17.0, jupyter-lab works fine). The console window in the devtools gives another hint:

The input spec uses Vega-Lite v5.8.0, but the current version of Vega-Lite is v4.17.0.
vega-embed@6?noext&v=20230520195653:6

Uncaught (in promise) Javascript Error: Failed to execute 'setAttribute' on 'Element': '0' is not a valid attribute name.
This usually means there's a typo in your chart specification. See the javascript console for the full traceback.

How can it load another Vega-Lite bundle? We define this here:

SCHEMA_VERSION = 'v5.8.0'
SCHEMA_URL = 'https://vega.github.io/schema/vega-lite/v5.8.0.json'

Which is loaded here:

VEGALITE_VERSION = SCHEMA_VERSION.lstrip("v")
VEGA_VERSION = "5"
VEGAEMBED_VERSION = "6"

If I save the spec that errors to a local html file it renders fine.

binste commented 1 year ago

I cannot reproduce this in a Jupyter Notebook on Altair 5. The HTML renderer should load the relevant Vega-Lite version in case another one is loaded, see https://github.com/altair-viz/altair/blob/master/altair/utils/html.py#L105.

@mattijn When you inspect the Notebook cell output in your browser, can you find the following part which comes from the HTML renderer and does it have the correct VL version 5.8?

image

When you look at the head of the HTML page, does it contain these 3 lines which should have been added by the HTML renderer?

<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="vega-embed" src="https://cdn.jsdelivr.net/npm/vega-embed@6?noext&amp;v=20230521080200"></script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="vega" src="https://cdn.jsdelivr.net/npm/vega@5?noext&amp;v=20230521080200"></script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="vega-lite" src="https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext&amp;v=20230521080200"></script>

Any error messages in the browser debugging console which could be related to it?

mattijn commented 1 year ago

I cannot reproduce it anymore.. The difference between now and yesterday evening is a restart of my machine🤷‍♂️

binste commented 1 year ago

@JanetMatsen Could you try clearing the output cells, clearing the cache of your browser, and then reloading the page where you have the notebook and executing it again? In case it still happens, could you use the Developer Tools in your browser to view the source code of the page and search in the head part of the page for vega-lite and copy paste the lines in here where it appears? Let me know if you'd need more detailed instructions.

I'm wondering if this can happen if some parts of a notebook were executed with Altair 4 and some with Altair 5 and then the header of that page might contain multiple script loads, i.e. not just the 3 lines I pasted above but the same for Vega-Lite 4. I hope in that case a reload of the page and clearing of all cell outputs should solve it.

JanetMatsen commented 1 year ago

I cleared the last 7 days of cache and the plot renders now. I suspect I didn't somehow have a mix of Altair 4 and Altair 5 installed, but maybe 🤷‍♀️ .

mattijn commented 1 year ago

Same feeling, thanks for the feedback. Somehow a browser cache issue. Great that it works now