SciRuby / iruby

Official gem repository: Ruby kernel for Jupyter/IPython Notebook
https://github.com/SciRuby/iruby
MIT License
890 stars 27 forks source link

Add support for jupyter widgets #350

Closed matt-do-it closed 1 day ago

matt-do-it commented 1 day ago

Currently it is not possible to display Jupyter widgets with an iruby kernel, as they require custom metadata on comm. This patch adds the ability to send metadata on open, send_msg, and close messages in a backward-compatible fashion.

As an example, you can now display an IntSlider with this example code, executed in a notebook. Please note the {:version => "2.1.0"} - this is metadata that has not been supported until now.

    comm = IRuby::Comm.new("jupyter.widget", comm_id = @id)

    comm.open({:version => "2.1.0"}, :state => {
        :dom_classes => [],
        :_model_module => "@jupyter-widgets/controls",
        :_model_module_version => "2.0.0",
        :_model_name => "IntSliderModel",
        :_view_count => nil,
        :_view_module => "@jupyter-widgets/controls",
        :_view_name => "IntSliderView",
        :_view_module_version => "2.0.0"
    })
kojix2 commented 1 day ago

Hi matt-do-it. Thank you for your pull request for IRuby. The IRuby project currently has no active developers. If you find any issues with the code, please send me an additional pull request.

kojix2 commented 1 day ago

Note: Currently, the tests are failing on Ruby 3.3 because warnings related to OpenStruct are being written to the standard error output. This is being captured by Open3.capture2e and then mistakenly parsed as JSON. Therefore, it seems unrelated to this pull request.