Giter VIP home page Giter VIP logo

Comments (7)

hanayik avatar hanayik commented on June 19, 2024

@kolibril13 , this looks great! I just ran it in a notebook locally and it worked well :). I think this approach significantly simplifies the development of the jupyter notebook integration.

I think the tricky part will be waiting for asynchronous NiiVue functions (for example: loadVolumes).

Also, it would be useful to keep NiiVue setter/getter methods in sync with the python API. Maybe a useful approach would be to develop the jupyter notebook integration in the same repo as the niivue package. Then we could share config files etc that keep the python API and the Javascript API in sync as NiiVue development moves forward (exact implementation TBD). So instead of setting w.value = "https://niivue.github.io/niivue-demo-images/mni152.nii.gz" the Python API would match the NiiVue API and it could look like this: w.loadVolumes([{"url", "https://niivue.github.io/niivue-demo-images/mni152.nii.gz"}])

What do you think?

We have a NiiVue development group meeting on 10th Jan at 3pm (London TZ). You're welcome to join and we can add this to the discussion. Email me at [email protected] for an invite.

from ipyniivue.

kolibril13 avatar kolibril13 commented on June 19, 2024

I think this approach significantly simplifies the development of the jupyter notebook integration.

that's great to hear!

I think the tricky part will be waiting for asynchronous NiiVue functions (for example: loadVolumes).

Can you tell me more what you mean by waiting for asynchronous function would be the tricky part?
This is probably something that can be investigated on the anywidget side by looking at a minimal example (e.g. async function with a simple timeout).

instead of setting w.value = "https://niivue.github.io/niivue-demo-images/mni152.nii.gz" the Python API would match the NiiVue API and it could look like this: w.loadVolumes([{"url", "https://niivue.github.io/niivue-demo-images/mni152.nii.gz"}])

sounds reasonable! Also, here it could help to make a minimal example with anywidget in order to figure out how to change a traitlet via function call.

NiiVue development group meeting on 10th Jan at 3pm (London TZ). You're welcome to join

Thanks for the invitation, I'm happy to join!

from ipyniivue.

christian-oreilly avatar christian-oreilly commented on June 19, 2024

Some preliminary thoughts. I don't know this framework, so some of my assumptions may be wrong.

Looking at the code, it seems like it is a state-based system, where state variables are created and then synchronized automatically between the Python and the JS side. From Python's side, I assume the "on_change" callback from the traitlet variables get triggered when theit values are updated. So, it looks like, on the Python side, state variables are updated and the framework takes care of updating the JS side accordingly. It is not clear to me how this can be extended to the re-use of JS functions from the Python side. Wrapping JS-side functions in Python (rather than just mapping the base arguments) might be desirable to avoid having to recreate the logic of these functions on the Python side. I am not sure if doing so requires circumventing the mechanisms used by anywidget and will cause the sync issues to pop back.

@kolibril13 The issues with waiting for asynchronous function have not been discussed consistently in one single issue, but are are the roots of many of the issues currently open. Issue #38 is probably a good example.

from ipyniivue.

christian-oreilly avatar christian-oreilly commented on June 19, 2024

@kolibril13 This post also captures well the issue: https://discourse.jupyter.org/t/synchronously-call-javascript-function-from-python/10059

from ipyniivue.

kolibril13 avatar kolibril13 commented on June 19, 2024

it seems like it is a state-based system, where state variables are created and then synchronized automatically between the Python and the JS side.

yep, that's right! I'm also planning to make a tutorial on anywidget that gives some minimal examples how to use them.
So far I've only made a tutorial for ipyreact (which is based on anywidget, so most things are similar: https://github.com/widgetti/ipyreact/blob/master/examples/full_tutorial.ipynb)

I assume the "on_change" callback from the traitlet variables get triggered when theit values are updated

exactly!

Wrapping JS-side functions in Python (rather than just mapping the base arguments) might be desirable to avoid having to recreate the logic of these functions on the Python side

Not sure I understand what you mean by this. Can you maybe give a minimal example?

from ipyniivue.

christian-oreilly avatar christian-oreilly commented on June 19, 2024

Wrapping JS-side functions in Python (rather than just mapping the base arguments) might be desirable to avoid having to recreate the logic of these functions on the Python side

Not sure I understand what you mean by this. Can you maybe give a minimal example?

@kolibril13 I meant the same thing that @hanayik said, i.e., using a function call (w.loadVolumes([{"url", "https://niivue.github.io/niivue-demo-images/mni152.nii.gz"}])) instead of an attribute update (i.e., w.value = "https://niivue.github.io/niivue-demo-images/mni152.nii.gz").

from ipyniivue.

christian-oreilly avatar christian-oreilly commented on June 19, 2024

Note for example that the current structure does not allow loading multiple volumes since the arguments of loadVolumes is built on JS side:
https://github.com/kolibril13/anywidget-ipyniivue/blob/0d39d180b1dcb1d9b139e11a914366174436e513/js/widget.jsx#L11-L16

from ipyniivue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.