Reusing ipywidget composite UI in solara
I am trying to reuse some ipywidget UI components with minimal rewrite in a new solara dashboard. I noticed that using a
display
function, and I am not sure where it is from since there is no explicit import. A prior question uses this in https://discord.com/channels/1106593685241614489/1232310547794628649. I used it to reuse displaying an ipyleaflet Map, with success, working by inference from another example https://huggingface.co/spaces/FranciscoGS/solara-geospatialDashboard/blob/main/pages/Servicios_apoyo.py#L106
.
I am now trying to apply the same recipe to display a list of ipywidget Datetime pickers and FloatSliders:
and the function is wrapped in a solara component
However this fails with the following stacktrace5 Replies
I am doing something wrong using
display
on a ipw VBox, perhaps. Any insight would be welcome.
Hey @J-M!
The
display
function can be imported from solara
, but we just hijack the IPython
one, so that one should work equally well. Like the stacktrace says, reacton is trying to render a widget into an element, but that widget has been closed since the render started. Is there any more context to the stacktrace when the widget was closed, or is it only this sys.exit(main())
call? For the reference, often if you want to avoid having to use display
, you can also append .element
to your widget calls, so
would become
Thank you @Iisakki Rotko . I think I can get by trying to use every ipywidgets one by one, using
.element
. I do not understand the widget lifecycle (python and JS sides) enough to understand why it is reported as closed. I thought the use of a global variable _simui = ui
to hold an indirect reference to all ipywidget
instances via ui
would prevent garbage collection (if this is a synonym of "closed") and keep widgets "alive".@J-M could you be using a global widget? The idea is that because multiple users share the same server, we need to isolate widgets from each user. A global widget can be a closed one, and might result in an error like this
THanks @MaartenBreddels and apologies for the belated reply. if by global widget you mean a static variable (class variable) I don't think so. I worked around this, perhaps for the better anyway. I'll see if I can make the time this month to write one or more blog posts on solara and give links.