# Webwidget Update on Slicer Events

**URL:** <https://discourse.slicer.org/t/webwidget-update-on-slicer-events/26553>\
**Category:** Development\
**Created:** [December 2, 2022, 2:32pm UTC](https://discourse.slicer.org/t/webwidget-update-on-slicer-events/26553 "2022-12-02T14:32:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![connorh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/connorh/32/79802_2.png) [@connorh](https://discourse.slicer.org/u/connorh)\
**Post date:** [December 2, 2022, 2:32pm UTC](https://discourse.slicer.org/t/webwidget-update-on-slicer-events/26553/1 "2022-12-02T14:32:09Z")

</div>

Hello,

I’m using a qSlicerWebWidget to display some interactive plots in Slicer. I’m wondering if there’s a way to call a method within my javascript/html when something changes in the Slicer scene (add a listener within the webwidget). For example, I would like to update what is displayed in my qSlicerWebWidget if a sequence in my Slicer scene changes frame, or if the crosshair moves.

Is there a way to do this without reloading the entire html and assigning it to the WebWidget? Or is the only available interaction between webwidget and Slicer `window.slicerPython.evalPython`?

I know I could achieve this my adding a listener within python and then re-loading the full HTML each time, I’m just trying to keep it fast.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 2, 2022, 4:02pm UTC](https://discourse.slicer.org/t/webwidget-update-on-slicer-events/26553/2 "2022-12-02T16:02:26Z")

</div>

Yes, you can communicate both ways. `window.slicerPython.evalPython` lets the JavaScript execute Python code in Slicer’s environment, and `qSlicerWebWidget.evalJS` lets Python or C++ code execute JS code.

You can connect to the `qSlicerWebWidget.evalResult` signal to get the result of your computation. Since the JS code runs asynchronously, the signal returns both the evaluated JS and the result so you can keep track of which code generated the result.

It’s all event driven and runs very fast.

> <https://github.com/Slicer/Slicer/blob/a5f75351073ef62fd6198d9480d86c0009d70f9b/Base/QTGUI/qSlicerWebWidget.h#L97>

> <https://github.com/Slicer/Slicer/blob/f368210d4a04db1eba0616f3ef88acafcd1ec1a2/Applications/SlicerApp/Testing/Python/WebEngine.py#L109-L221>
