Open crazycapivara opened 3 days ago
Same for using marimo.ui.anywidget
.
To bring anywidget into marimo's reactive system, you'll need to wrap it in mo.ui.anywidget
m = MapWidget(map_options)
m.use_message_queue(False)
m.add_control(NavigationControl())
m.add_deck_layers([deck_grid_layer])
map = mo.ui.anywidget(m)
map
In order for the downstream cell's to re-render based off the reactive changes from w
, you'll need to pick the values off that instead of m
.
map.value["clicked"]
or you can force the dependency between cells by doing something like:
map.widget.clicked
We can look into making anywidget more tightly integrated without having to wrap marimo.ui.anywidget
Hi, yes I know and I first did it this way and w.value
works fine but I need it the other way round. I need to update the widget itself from Python, e. g. to update layer properties after it was initially rendered. In the example I provided I wanted to add a ScaleControl after the widget was rendered. This is done via Anywidget.send
method.
Maybe only model.on("change:my_value")
is supported?
Oh sorry - I read this fast and started with your re-production code, which didn't have .send
- but i see now, its from add_control(ScaleControl())
.
I can look into getting .send
working, but this feels like mutating state which usually does not play nicely in a reactive environment.
I can see the value of .send
in other contexts (button click or conditionals). We can look into supporting this, but as of now, we don't have any existing mechanism for python widgets to send data to their frontend counterpart after rendering (we do if they request it, as an RPC), but not a plain bi-directional connection.
Describe the bug
Anywidget.send
does not update the widget.I tried to render maplibre widget which is based on
anywidget
. The initial rendering works, but if I try to update the widget which internally usesAnywidget.send
method nothing happens. In th Js Developer console I can see that the custom message is not send.Environment
Code to reproduce