Comments (7)
@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.
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.
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.
@kolibril13 This post also captures well the issue: https://discourse.jupyter.org/t/synchronously-call-javascript-function-from-python/10059
from ipyniivue.
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.
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.
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)
- ipyniivue installting correctly but viewer window not showing up
- a
- Graph features
- Add custom colormaps
- devDependency requirement on @jupyterlab/builder@^4.0.0
- load_meshes HOT 1
- Building documentation HOT 8
- Review code of NiiVue Jupyter notebook integration in IPyNiiVue HOT 4
- load_meshes does not add the mesh to self.meshes in MacOS and Linux HOT 5
- Restarting the kernel fails to destroy the NiiVue object
- jupyterlab 4 support HOT 4
- ENH: Integration with MNE-Python
- Possible to add overlays and/or possibly saving the whole scene as .html file to harddrive?
- Project admin, milestones, and roadmap
- Priorities HOT 6
- ☂️ Volume HOT 9
- Better camel/snake scale conversion HOT 10
- Exposing `nv.saveScene` on the python side HOT 1
- Deleting big files HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipyniivue.