-
Notifications
You must be signed in to change notification settings - Fork 51
add jupyter-sidecar as a dependency, update simple notebook #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
idea: what if automate the sidecar part with a kwarg to plot.show(sidecar=True) # default is True
# if there should be some kwargs passed to sidecar, such as the title for it etc.
plot.show(sidecar=True, sidecar_kwargs={...}) In |
What happens when you run the tests? Does sidecar interfere with creating the screenshots? |
tests passing locally for me, just needed to add |
I think this would be cool bc it alleviates having to have:
also would be nice to have Maybe each plot instance would have a |
You will need to figure out how sidecar works with mulitple Thoughts to get you started:
|
Interesting find today, multiple calls of with sc:
display(plot.show()) across different running notebooks will open the different plots in the same sidecar with different tabs |
closing the sidecar does NOT close the plot, can then be re-rendered either in another sidecar or in a cell |
if you close the sidecar with "x", then the sidecar instance has been closed and subsequent calls to with sc:
display(plot.show())) does nothing |
With all of the above comments in mind: I think it is most relevant to have: plot.show(sidecar=True, sidecar_kwargs={...}) and should function as follows:
|
@kushalkolar added sidecar for plot to start, two issues:
Cell In[17], line 2
1 # testing cell, ignore
----> 2 plot_test("astronaut", plot)
File ~/repos/fastplotlib/examples/notebooks/nb_test_utils.py:32, in plot_test(name, plot)
29 regenerate_screenshot(name, snapshot.data)
31 try:
---> 32 assert_screenshot_equal(name, snapshot.data)
33 except AssertionError:
34 FAILURES.append(name)
File ~/repos/fastplotlib/examples/notebooks/nb_test_utils.py:44, in assert_screenshot_equal(name, data)
41 def assert_screenshot_equal(name, data):
42 ground_truth = iio.imread(SCREENSHOTS_DIR.joinpath(f"nb-{name}.png"))
---> 44 is_similar = np.allclose(data, ground_truth)
46 update_diffs(name, is_similar, data, ground_truth)
48 assert is_similar, (
49 f"notebook snapshot for {name} has changed"
50 )
...
File ~/venvs/mescore/lib/python3.11/site-packages/numpy/core/numeric.py:2356, in isclose.<locals>.within_tol(x, y, atol, rtol)
2354 def within_tol(x, y, atol, rtol):
2355 with errstate(invalid='ignore'):
-> 2356 return less_equal(abs(x-y), atol + rtol * abs(y))
ValueError: operands could not be broadcast together with shapes (269,449,4) (300,500,4) must have something to do with canvas size vs the snapshot, perhaps snapshots just need to be regenerated? |
nonetheless, sidecar is functional for a single plot as so: # create a `Plot` instance
plot = Plot()
# get a grayscale image
data = iio.imread("imageio:camera.png")
# plot the image data
image_graphic = plot.add_image(data=data, name="sample-image")
# show the plot
plot.show(sidecar_kwargs={"title": "sample image", "layout": {'width': '800px'}}) wanted to get your thoughts before implementing in gridplot and imagewidget |
This sounds good to me! Is the 3rd point functional in the current implementation? |
works with current implementation, see comments in code...used a cheat code for now not sure if it is best implementation but I couldn't figure out in juypter sidecar how to get access to the close button in order to add a observe method on click also updated the simple notebook with your changes |
still getting error that I mentioned above ab mismatched sizes between canvas and screenshot, even though I regenerated them and ran the tests locally and they passed...but they fail in those cells you have in the notebook |
current implementation for @kushalkolar I think this makes sense? To me, you would only want to not have the toolbar if you are not rendering in Jupyter. I could not imagine wanting to use sidecar and not have the toolbar...thoughts? Can update the logic, but not sure it is necessary. Other: Should we implement |
Yes this makes sense, I think that if someone wants sidecar but no toolbar that's such a bizarre cornercase. If they don't want toolbars in jupyter in general that's a weird cornercase and they're probably trying to make their own thing, in which case they can customize it themselves
Yes sounds good :D |
# validate vbox if not None | ||
if vbox is not None: | ||
for widget in vbox: | ||
if not isinstance(widget, Widget): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can use Widget
or any ipywidget imports directly within show()
because if ipywidgets
is not installed in the environment (if they are using fastplotlib with only glfw
or Qt
), this will raise a error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just put it in the VBox
and let VBox
deal with it if it's not the right type.
if not sidecar: | ||
return VBox([self.canvas, self.toolbar.widget]) | ||
if self.vbox is not None: | ||
return VBox([self.canvas, self.toolbar.widget, self.vbox]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the previous comment, I just realized that we can't use VBox
in show()
because it'll raise an error if using in an environment without ipywidgets
. Perhaps we need to split show()
into show_desktop()
and show_notebook()
?
Or have two subclasses of PlotFrame
, one for notebook and one for desktop, I think this will be the cleaner solution.
So this has an issue where it will not work on desktop, but we need to fix that with #310 since this PR has already gotten long. |
closes #299
Only updated
simple.ipynb
because the other ones are pretty short