Does anyone know how I might interact
Does anyone know how I might interact with anywidgets widgets in solara? I can make one:
Then since it uses traitlets I can set up an observer to do something when the value changes (including for e.g. updating a solara reactive variable to keep them in sync). BUT: to show the widget in a solara app I have to use
counter = CounterWidget().element()
but this makes it much harder to then figure out how to get the value (I'm not familiar with whatever magic .element does yet).
This (traitlets etc) doesn't even feel like quite the right approach - perhaps someone more familiar with anywidgets can give a tip on the quickest way to have some shared state between custom javascript and solara?5 Replies
Ah I see one mistake I was making was using
counter = CounterWidget().element()
not counter = CounterWidget.element()
CounterWidget.elements(value=r.value, on_value=r.set) where r is a reactive value.
This should work.
@alonsosilva you just wrote a blog post about this right?
This is what I had which sort of worked (ckicking the custom widget updated the markdown, but resetting the reactive variable count didn't reset the custom widget. Just seen your message, will try
Yes that works
^^ If anyone wants the solution
Many thanks @MaartenBreddels
Yes, and I did that mistake as well! After this discussion, I have updated the blog post by adding how to access the anywidget counter https://alonsosilvaallende.github.io/blog/posts/2024-04-23-Build_a_basic_widget_with_AnyWidget.html
Fantastic post, came for the content stayed for the satisfying confetti 😄