Skip to content

Conversation

@ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Sep 22, 2025

Migrate Vega validation from Lumen https://github.com/holoviz/lumen/blob/main/lumen/ai/views.py#L245-L262 into Panel.

Also handles archaic error:
Closes #8201

@ahuang11 ahuang11 requested a review from philippjfr September 22, 2025 19:11
self._update_selections()

@cache
def _download_vega_lite_schema(self, schema_url: str | None = None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about airgapped usage of panel? Are we not trying to support that?

Copy link
Contributor Author

@ahuang11 ahuang11 Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_download_vega_lite_schema is optional--only for validation.

            try:
                schema = self._download_vega_lite_schema(schema)
            except Exception as e:
                self.param.warning(f"Skipping validation because could not load Vega schema at {schema}: {e}")
                return

And users have full flexibility on using a local schema, meaning it can do something like: requests.get("localhost:8000/schema")?

However, potentially I can do open("schema").read()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, open("schema").read() isn't feasible because I don't think the JS can access it, but if user exposes it as an endpoint, it's likely doable.

import json
import requests

with open("schema.json", "w") as f:
    json_file = requests.get("https://vega.github.io/schema/vega-lite/v5.json").json()
    json.dump(json_file, f)

import panel as pn
pn.extension('vega')

vegalite = {
  "$schema": "schema.json",
  "data": {"url": "https://raw.githubusercontent.com/vega/vega/master/docs/data/barley.json"},
  "mark": "bar",
  "encoding": {
    "x": {"aggregate": "sum", "field": "yield", "type": "quantitative"},
    "y": {"field": "variety", "type": "nominal"},
    "color": {"field": "site", "type": "nominal"}
  }
}
vgl_pane = pn.pane.Vega(vegalite, height=240)
vgl_pane.show()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At minimum this needs a timeout.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, open("schema").read() isn't feasible because I don't think the JS can access it, but if user exposes it as an endpoint, it's likely doable.

Should a remark / example regarding air-gapped use be added to the Vega doc after this update?

Looks like that info is currently not part of the doc.

https://panel.holoviz.org/reference/panes/Vega.html

Copy link
Collaborator

@Coderambling Coderambling Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related regarding air-gapped use: #7429

@ahuang11 ahuang11 changed the title Improve Vega Lite Improve Vega Lite to support validation Sep 22, 2025
@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

❌ Patch coverage is 93.24324% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.24%. Comparing base (b749842) to head (5e884b5).

Files with missing lines Patch % Lines
panel/pane/vega.py 92.06% 5 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (b749842) and HEAD (5e884b5). Click for more details.

HEAD has 5 uploads less than BASE
Flag BASE (b749842) HEAD (5e884b5)
12 7
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #8215       +/-   ##
===========================================
- Coverage   86.01%   70.24%   -15.78%     
===========================================
  Files         348      347        -1     
  Lines       54378    54451       +73     
===========================================
- Hits        46775    38249     -8526     
- Misses       7603    16202     +8599     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Successfully merging this pull request may close these issues.

Confusing Vega error without $schema part of the spec

6 participants