ankane / vega-ruby

Interactive charts for Ruby, powered by Vega and Vega-Lite
BSD 3-Clause "New" or "Revised" License
257 stars 9 forks source link

Example Vega.lite bar chart does not render in IRuby Jupyter notebook #8

Open dorra opened 2 years ago

dorra commented 2 years ago

iruby 0.7.4 ruby 3.0.4 vega-ruby 0.2.6 jupyter lab 3.3.2

Notebook command:

Vega.lite
  .data([{city: "A", sales: 28}, {city: "B", sales: 55}, {city: "C", sales: 43}])
  .mark(type: "bar", tooltip: true)
  .encoding(
    x: {field: "city", type: "nominal"},
    y: {field: "sales", type: "quantitative"}
  )

vega-ruby creates html code

Bildschirmfoto 2022-06-20 um 23 16 34

html code is not rendered in jupyter lab

Bildschirmfoto 2022-06-20 um 23 16 46

This might be an issue of jupyterlab? Daruview with googlecharts renders fine.

ankane commented 2 years ago

Hey @dorra, thanks for reporting. It looks like RequireJS isn't included in JupyterLab, which is causing an error. Not sure when I'll be able to put together a fix, but it should work in Jupyter Notebook in the meantime.

dorra commented 2 years ago

Hi @ankane - thank you for the swift reply. Yes, it seems to work in every other client or environment than jupyter lab. That's a real shame, we are in the process of building a data analysis environment. A server oriented environment is useful ;) Thanks for your great open source contributions!

dorra commented 2 years ago

@ankane here is an interim solution:

require 'net/http'
require 'vega'
IRuby.html "<script>#{Net::HTTP.get(URI('https://requirejs.org/docs/release/2.3.6/minified/require.js'))}</script>"
Vega.lite
  .data([{city: "A", sales: 28}, {city: "B", sales: 55}, {city: "C", sales: 43}])
  .mark(type: "bar", tooltip: true)
  .encoding(
    x: {field: "city", type: "nominal"},
    y: {field: "sales", type: "quantitative"}
  )
ankane commented 2 years ago

Quick update: it looks like Jupyter Lab has built-in support for Vega/Vega-Lite, but haven't had any luck getting it working with Ruby.