Missing example of use of RequireJS for vega-embed
See original GitHub issueHi, I would like to dynamically load vega-embed and all its dependencies (vega and vega-lite, which themselves depend on d3, etc.) using the RequireJS library. From previous discussions (see https://github.com/vega/vega/issues/171 among else) I know that vega and D3 are AMD-compatible, so this ought to be doable.
What I am missing is an example of use of vega-embed with RequireJS. The code below throws errors, and I’m not sure if it is due to an incompatibility of vega-embed with RequireJS or my incorrect use or the later library:
requirejs.config({
paths: {
d3: "https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.min.js?noext",
d3_geo_projection: "https://cdnjs.cloudflare.com/ajax/libs/d3-geo-projection/0.2.16/d3.geo.projection.min.js?noext",
d3_layout_cloud: "https://vega.github.io/vega-editor/vendor/d3.layout.cloud.js?noext",
topojson: "https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.20/topojson.min.js?noext",
vg: "https://cdnjs.cloudflare.com/ajax/libs/vega/2.5.1/vega.min.js?noext",
vl: "https://vega.github.io/vega-lite/vega-lite.js?noext",
vg_embed: "https://vega.github.io/vega-editor/vendor/vega-embed.js?noext"
},
shim: {
vg_embed: {deps: ["vg", "vl"]},
vl: {deps: ["vg"]},
vg: {deps: ["d3", "d3_geo_projection", "d3_layout_cloud", "topojson"]},
d3_geo_projection: {deps: ["d3"]},
d3_layout_cloud: {deps: ["d3"]}
}
});
require(["vg", "vl", "vg_embed"], function(vg, vl, vg_embed) {
var vg_specification = {
mode: "vega-lite",
spec: {
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
{"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
{"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
}
}};
vg.embed("#vis", vg_specification,
function (error, chart) {
chart({el:"#vis"}).update();
});
});
This throws a TypeError: Cannot read property 'util' of undefined
and TypeError: Cannot read property 'embed' of undefined
.
Best, Aurélien
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:18 (8 by maintainers)
Top Results From Across the Web
08-Configuration.ipynb.txt - Python — Altair
We'll use a simple datasets of normally-distributed points:" ] } ... For example: in the case of circles, the radius is determined in...
Read more >Trouble diplaying Altair chart on jupyter notebook
Error loading script: Script error for "vega-embed" http://requirejs.org/docs/errors.html#scripterror. I've tried clearing the cache and ...
Read more >ReVize: A Library for Visualization Toolchaining with Vega-Lite
ReVize makes use of Vega-Lite as a common exchange format to be able to add toolchain support to web-based tools. In contrast to...
Read more >CIS Fraud Detection(Visualize+Feature Engineering) | Kaggle
As you can see, 88% of values are missing and 10% of them are equal to 0. So, 98% of data is either...
Read more >qurro - Python Package Health Analysis | Snyk
Visualizes differentially ranked features and log-ratios of their sample abundances For more information about how to use this package see README.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you @tanyaschlusser for posting the code!
Vega-Embed should now be compatible with requirejs. I made some major improvements by switching to rollup. See https://beta.observablehq.com/@domoritz/hello-vega-embed for an example.
I think the paths above are necessary to tell require where to find the libraries.