Skip to content
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

Static Image Export in Python #627

Open
harrylojames opened this issue Dec 9, 2024 · 3 comments
Open

Static Image Export in Python #627

harrylojames opened this issue Dec 9, 2024 · 3 comments

Comments

@harrylojames
Copy link

Hi,

Would it be possible to have static image export functionality similar to that found in Plotly (https://plotly.com/python/static-image-export/)?

  • function to export static image
  • an interactive button to download a screenshot of the current context

There was some similar work done on the great package pyobsplot which also interacts with Observable Plot if of help. juba/pyobsplot#32

@domoritz
Copy link
Member

domoritz commented Dec 9, 2024

Can you explain how that would work from python and how interactivity works with that? I'm also not sure whether we can even support python since we just support widgets in Jupyter and so maybe the functionality should be there? Or are you saying you want a feature to get a rendered chart in a notebook environment?

Right now, I'd recommend printing the website which you can also do from something like playwright.

@harrylojames
Copy link
Author

Apologies for the ambiguity I'll try expand.

"Or are you saying you want a feature to get a rendered chart in a notebook environment?"

Once the chart has been rendered in a notebook environment I am envisioning the below.

image

While I can get a one off screenshot say using devtools or just manually the use case was that if I share the notebook with someone is there an easy way for them to grab a particular image.

"I'm also not sure whether we can even support python since we just support widgets in Jupyter and so maybe the functionality should be there? "

I don't know enough about anywidget to know if it should live there but it certainly could be a broadly applicable feature. Assuming that was what you meant.

"Can you explain how that would work from python and how interactivity works with that?"

Not sure what the cleanest way to achieve this would look like... The behaviour could be something like:

MosaicWidget(spec, data = {"weather": weather}, path = "output.png")

Where if a path is provided it simply exports a static image.

Or:

fig = MosaicWidget(spec, data = {"weather": weather}, path = "output.png")
fig.export("output.png")

Of course this is foregoing any interactivity it just takes the initial view. This to me is still useful as it means I can work with one tool and syntax for both interactive work and when needing to compile figures for print.

Hope that provides some more clarity. These could be split into two separate issues if helpful.

@domoritz
Copy link
Member

domoritz commented Dec 9, 2024

Ahh, thanks for the details. I think we could support a button in the web view to download an image with something like https://stackoverflow.com/questions/6887183/how-to-take-screenshot-of-a-div-with-javascript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants