niivue / ipyniivue

A WebGL-powered Jupyter Widget for Niivue based on anywidget
BSD 2-Clause "Simplified" License
25 stars 8 forks source link

Synchronize widget displays across multiple cells #15

Closed AnthonyAndroulakis closed 1 year ago

AnthonyAndroulakis commented 1 year ago

Describe the bug When displaying the same Niivue widget twice, interactions with the 1st Niivue widget do not update the display of the 2nd Niivue widget. Instead, what occurs is that the 1st Niivue widget freezes and does not respond to any interactions.

To Reproduce Steps to reproduce the behavior:

  1. follow the installation instructions here: https://github.com/niivue/ipyniivue#installation
  2. run the example notebook. This will display the same Niivue widget in 2 cells where you can see this bug occur.

Expected behavior Interactions in the 1st Niivue widget display should update both the 1st and 2nd Niivue widget displays (and all other displays of the same widget).

hanayik commented 1 year ago

@AnthonyAndroulakis, I jus tried to replicate this on my machine, but I'm not able to get things running properly. Are the current install instructions complete? What are the python environment dependencies?

AnthonyAndroulakis commented 1 year ago

I'd forgotten to add the numpy dependency to the pyproject.toml (just added it) so that could have been the issue. What errors did you come across?

hanayik commented 1 year ago

No errors in the notebook (or terminal from what I can tell), but the niivue canvas does not appear in a cell when I run it. Also, after running yarn run watch things seem to hang indefinitely. Is that expected with the watch command?

Can you provide step-by-step instructions for how to setup your python environment? Do you use conda, or python virtual envs?

AnthonyAndroulakis commented 1 year ago

Hm, do any errors show up in the developer console in the browser that you're using?
Yes, it's expected behavior for yarn run watch to continue running. This command is used for watching for updates in the code and rebuilding as necessary. If you'd like to simply build the code you can run yarn run build and then do jupyter lab.
I haven't set up ipyniivue in a virtual environment today - I'll try to get that working today.

AnthonyAndroulakis commented 1 year ago

I updated the installation instructions to use a conda environment. I was able to reproduce this bug and I created another issue about this display problem: #16

AnthonyAndroulakis commented 1 year ago

So I looked at this issue again (the synchronizing widget displays issue). It seems the reason why the cells do not synchronize is that Niivue can only attach to 1 canvas. Therefore, there are a few solutions to this issue:

Anyone have other ideas?

hanayik commented 1 year ago

Have a look at this demo for syncing niivue canvases (take a look at the source code). Does that demo display the behaviour you want? If so, then niivue can already sync two separate instances.

https://niivue.github.io/niivue/features/sync.mesh.html

From: Anthony Androulakis @.> Date: Saturday, 14 January 2023 at 12:28 pm To: niivue/ipyniivue @.> Cc: Taylor Hanayik @.>, Comment @.> Subject: Re: [niivue/ipyniivue] Synchronize widget displays across multiple cells (Issue #15)

So I looked at this issue again (the synchronizing widget displays issue). It seems the reason why the cells do not synchronize is that Niivue can only attach to 1 canvas. Therefore, there are a few solutions to this issue:

Anyone have other ideas?

— Reply to this email directly, view it on GitHubhttps://github.com/niivue/ipyniivue/issues/15#issuecomment-1382727175, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABHZ3OAQDM2DTQI3TEO7HADWSKLYVANCNFSM6AAAAAATYSXD4U. You are receiving this because you commented.Message ID: @.***>

AnthonyAndroulakis commented 1 year ago

That could work, the only "issue" I see is that nv1.setMeshThicknessOn2D does not update both nv1 and nv2 but I'll try it out and see how it goes. Thank you

AnthonyAndroulakis commented 1 year ago

Closed as intended behavior. See https://github.com/niivue/ipyniivue/blob/main/docs/development-notes/cell-syncing.rst