-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ipyreact.define_module
#160
Comments
After investigating this with @machow, we discovered |
I did some more digging, and wonder if this issue is related to #163. It seems like the challenge is this:
Here's an example app, where explicitly rendering a Module representing reactable's javascript code allows it to be rendered. from shiny.express import ui
from reactable import Reactable
from reactable.data import cars_93
from shinywidgets import render_widget
import ipyreact
# setup ----
from pathlib import Path
from importlib_resources import files
STATIC_FILES = files("reactable.static")
ui.include_css(Path(str(files("reactable.static") / "reactable-py.esm.css")))
# render the module in order to create the dependency -----
# normally this is just defined inside reactable-py, and picked up automatically
# but explicitly rendering it registers dependency (but has side-effect of outputting UI)
@render_widget
def out2():
mod = ipyreact.define_module("reactable", Path(str(STATIC_FILES / "reactable-py.esm.js")))
return mod
# table we want to render ----
@render_widget
def out():
from shinywidgets._dependencies import jupyter_extension_destination, jupyter_extension_path
Reactable(cars_93).to_widget() I wonder if part of the issue with #163 is that ipyreact is instantiating widgets on import, which jupyter (and by extension quarto) end up using (these seem sort of like "shadow widgets" or something?). |
@maartenbreddels is there any chance you might be able to help give a sense for how ipyreact handles the Module widgets created by I'm trying to figure out what triggers their "rendering". I noticed that I'm loving ipyreact, and super close to getting reactable-py out the door! It works really nicely in solara, so I'm guessing there's some small piece I've overlooked here 😓. |
I’m without a keyboard, but I can give some short hints. Solara avoids the global widgets by monkey patching define_module: Maybe using the same code in shiny will also work. Good luck, I can elaborate more next week when I’m behind a keyboard again. Regards, Maarten |
Ah, thanks -- this is helpful to see! Looking closer, I'm realizing that maybe the key here is what ipywidgets.Widget does on initialization. It looks like...
The issue comes then, because this is never run by py-shinywidgets, since...
It sounds like, once it's ready, shinywidgets should run through all the widgets it no-op'd and run their on_widget_constructed hook (or something?). I.e.
|
Here's a minimal example using shiny's from shiny.express import ui
from shiny import reactive
from reactable import Reactable
from reactable.data import cars_93
from shinywidgets import render_widget
import ipyreact
from pathlib import Path
from importlib_resources import files
STATIC_FILES = files("reactable.static")
ui.include_css(Path(STATIC_FILES / "reactable-py.esm.css"))
# Reactive calc: define the reactable Module -----
@reactive.calc
def out2():
# Module needs to be created here, because shiny won't run the on construction hook, until the
# shiny app is running, and that is after all the code is initially run...
mod = ipyreact.define_module("reactable", Path(str(STATIC_FILES / "reactable-py.esm.js")))
return mod
# Uses the calc before rendering, to ensure the Module is loaded ----
@render_widget
def out():
out2()
return Reactable(cars_93).to_widget() |
ipyreact.define_module
ipyreact.define_module
ipyreact.define_module
Description
Currently, I'm using ipyreact to create interactive tables in reactable-py. ipyreact is built on Anywidget, and I noticed there's quak support here, but I was unable to get ipyreact react to work 😓 .
What I Did
Note that in the express app below, I could see a div prepared for the widget, but no content:
I double checked some of the
shinywidgets._dependency
pieces, and it looks like it's finding / loading the necessary javascript. However, I'm not what might be different about ipyreact here 😬edit: updated example to import ipyreact first. importing after shiny widgets was causing an error (see #163)
The text was updated successfully, but these errors were encountered: