ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Running in Reticulate in IRKernel

Open orenbenkiki opened this issue 3 years ago • 1 comments

Problem

I want to have an R jupyter notebook, using ggploty for interactive plots, and also to have widgets to control certain parts of the code.

Looking at #792 which is 6 years old, there's no good solution:

  • Yes, ggplotly gives us interactive plots. However interactive plots != widgets.
  • The declerativewidgets package has been "retired" 5 years ago.

Proposed Solution

  • Run ipywidgets inside reticulate inside IRKernel - this works, at least it doesn't crash.

  • Somehow pass the widget HTML to IRKernel to be displayed - I couldn't figure out this part but it "should" be possible?

  • Then access the user-modified widget state from R code, probably via reticulate to access the Python accessible widget state - I'm wildly guessing here but this "should" also be possible?

Additional context

A possibity which does work is to use rpy2, that is:

  • Run a Python jupyter notebook
  • Run ipywidgets, collect the widget state
  • Use rpy2 to invoke the R code, wrapped inside robjects.r.

The problem is that we end up with a Python notebook where every cell looks like robjects.r(''' ... lots of R code '''), giving up on all the R-specific features (syntax highlighting, autocompletion, etc.).

orenbenkiki avatar May 07 '22 07:05 orenbenkiki