I am trying to run a simple script in WebPPL using the command line, which runs the following visualization:
var fairCoin = function() { flip(0.5) ? 'h' : 't' };
viz(repeat(20, fairCoin))
Following the instructions on the GitHub repo, I have installed webppl, and have also installed webppl-viz by running npm install probmods/webppl-viz
in the folder ~/.webppl
. I also installed node-canvas in the same folder by entering npm install canvas
. However, I get the following error:
/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:18
return g2D || (g2D = canvas.instance(1,1).getContext('2d'));
^
TypeError: Cannot read property 'getContext' of null
at context (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:18:44)
at textMark (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:169:11)
at Object.itemBounds [as item] (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:259:3)
at /Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega/src/scene/Bounder.js:36:13
at Array.forEach (<anonymous>)
at Bounder.proto.evaluate (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega/src/scene/Bounder.js:35:15)
at Model.prototype.evaluate (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega-dataflow/src/Graph.js:329:16)
at Builder.proto.evaluate (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega/src/scene/Builder.js:227:26)
at Model.prototype.evaluate (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega-dataflow/src/Graph.js:329:16)
at Model.prototype.propagate (/Users/sambarnett/.webppl/node_modules/webppl-viz/node_modules/vega-dataflow/src/Graph.js:161:22)
I suspect this is due to some of the dependencies not being installed properly, although I can't see how to fix this. I know that the WebPPL script runs correctly in the browser.