posit-dev / py-shinywidgets

Render ipywidgets inside a PyShiny app
MIT License
41 stars 2 forks source link

"No model found for id {x}" when rendering dynamically #108

Open jcheng5 opened 8 months ago

jcheng5 commented 8 months ago

Description

With this app I was trying to have a widget returned from a UI output. But no widget appears, and there's a JS error saying "No model found for id {whatever}".

It looks to me like the fact that the widget registration happens before the output_widget is bound, is something shinywidgets didn't expect?

cpsievert commented 8 months ago

For now, you can workaround this problem by statically rendering output_widget()'s HTML dependencies, for example:

app_ui = ui.page_fluid(
    output_widget("foo").get_dependencies(),
    ui.output_ui("dynamic_ui"),
    ui.output_text("value")
)

I haven't looked deeply yet at what is causing this, but based on the fact that the simple dynamic UI usage works fine, it seems the issue derives from register_widget() getting called before the output binding has been registered (i.e., before output_widget()s dependencies have rendered).

PS. I'm not totally sure if it'll make sense for {shinywidgets} to "just work" with this sort of usage. In the case that it doesn't, it feels like there should be a use_shinywidgets() (which would a thin wrapper around output_widget("foo").get_dependencies())...