-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Directly save image (without opening in browser) #880
Comments
This is now supported 🎉 https://medium.com/@plotlygraphs/plotly-py-end-of-summer-updates-5422c98b9058 |
@cldougl since this is still open, could we do a quick thought experiment? Let's say the Like would you need to do this in pure As @geniusupgrader referenced, there's issues on this already, and I'll add that there's activity on the forums and at least a couple of posts on SO about this. The community wants this. I want this... but I'm newer to So, my pitch is that if you could help the community to understand what a possible solution might look like instead of just closing issues outright, perhaps they would do it for you! Just an [optimistic, idealist] thought :) I submitted a feature request to this effect though it appears plotly screens them as mine isn't showing up. |
I just fiddled with this a bunch and I think there are at least two possible methods:
I demonstrated the feasibility of this here. I tested minimally, so I'm not sure what the limitations are. I was surprised that basically copying
Ultimately, I didn't actually need to use a button click. We just need to specify Unknowns abound: os portability, plot type/size limitations, other system variables, dependency availability across os's and how complex it would be to detect them. Still... I'm feeling pretty good. I consider myself not at all good at Would you consider implementing something like this if you tell me where it could go in the api structure and I create a PR? |
Thanks for your contribution @jwhendy!
Is this a limitation of selenium that it can't handle |
thanks for raising this issue again. I tried @jwhendy methods but in the way I'm using Plotly Python API it seems not feasible (https://github.com/ghtmtt/DataPlotly). If someone is taking care to find a solution, please consider me as help/tester. Having also this feature would be awesome |
@geniusupgrader thanks for the feedback. I certainly don't love either of them myself, but I'm not sure how to go about it otherwise.
Indeed... one would think so. I will say, from my noob perspective these are notable data points:
In other words, if this is possible, it's intriguing that two legit solutions out there did not use it and opted for these sort of painful and dependency-heavy workarounds. Good feedback on the Re. the error, it appears it's just a limitation of Try opening in a different viewer (or browser) and you should see it! Also, from looking around, it seems I could have just done this instead:
|
it should be an end product, so no modification after the download is needed |
Another idea was to run the
Looking around for how to call There is a node interface, but it requires providing a username and api key, so it defeats the purpose of offline image export. @geniusupgrader
I don't understand. I wanted to know "why |
@jwhendy I step into the discussion "why |
@jwhendy vector format is (most of the times) definitely better for plots, cause scalable and such |
In lieu of something better, feel free to tinker around with my You'd use it like this:
Some ideas for improvement/testing:
@ghtmtt sorry this might not work for your case! I'm pretty stumped other than what I've found :( @geniusupgrader understood re. |
@jwhendy thanks again for your effort. In regard to |
Happy holidays @jwhendy @bluprince13 @geniusupgrader ! Just wanted to let you know that Plotly is aware of this issue. We're currently testing a new image server on plotly cloud against more than 5 million user generated charts. If this goes well, we plan to open-source and package this server for easy, cross-platform use by Python users. Timeline is hopefully late February for a release.
TLDR; We're using Electron for the new image server. The previous image server on Plotly Cloud and Plotly On-Premises used Batik for vector images (PDF, SVG, EPS) and node webkit for raster images (PNG, JPEG). The Electron rewrite has simplified things to an extent where we feel comfortable maintaining this as a pip installable library for Python users without (hopefully) a nightmare of issues related to complexities you've already mentioned - cross-platform support, font families, sprawling dependencies, etc. Stay tuned. This is taking a while, but we are taking the time to do it right. I'll try to update this issue as things get closer! |
👋 @jwhendy @bluprince13 @geniusupgrader and others Googling into this issue - Wanted to share an update since it's been 2 months:
|
Download and setup a dedicated process so I can export to png? |
FYI this is now possible with one line after setting your data and figure: edit [051518]: actually this doesn't work :/ data = Data([tasks, tasks2, tasks3]) It saves to the /Downloads directory. https://gist.github.com/amaIgam/c441ffa88a90a8a360d771fae3ba2d8e Looking for a way to change that default directory currently... |
@eagleEggs not exactly. In your example it will work with an IPython notebook, not as pure python code |
True. A bit later I realized that the result was either from a Jupyter test I did, or from Firefox alerting that there was already a window open and it initiated the download anyway. Unfortunately the latter is not easily controllable or stable... I was hoping that someone would answer with the solution at this point though :) For now I switched my plotting to matplotlib. |
Hello - I've been watching this, and #483 for a while. I like very much the new perspective of allowing offline image export in plotly. Also the development on orca is great news ! @jwhendy, you mention above the possibility to use phantomjs for taking 'webshots' of html files. This is how the R community has implemented the export, and this is how I do my offline exports to both PNG and PDF (python port at https://github.com/mwouts/plotly_offline_export). The approach cannot compete with orca, but still it has very few dependencies (just phantomjs) and it works pretty well - only issue I found over hundreds of plots exported was with long legends which were truncated. |
@jwhendy, yes I had a look at your plotly fork (I also had seen this attempt based on selenium). @jackparmer, yesterday I tried to install orca with |
In our experience, Electron is going to be much more reliable. We'd also like to officially support only a single way to create these images and that is going to be through our Orca project.
Soon! For now, check out the latest releases of Orca here: https://github.com/plotly/orca/releases |
It seems that orca is the recommended way to save images from plotly graphs and the like. But I dunno if I should close this issue? Thoughts? |
Well, I think the issue should only be closed when plotly provides its own method for saving plots - as long as that's in the long-term plan. |
Yeah, it seems like what folks really want here is for Orca to be bundled with plotly.py, so that they don't have to install 2 different things. @jmmease was taking a look at this for the plotly.py 3.0 release, though it would likely happen after this release. |
My current thought is that we'll add a new image export entry point to plotly.py that will require orca to be installed on the system (And if it's not installed we'll raise an error message with instructions). pip users will follow the instructions on the orca README (install either using npm or using the particular OS installer). For conda users, can build an orca package and eventually make it a dependency of the plotly.py conda package (unless we decide orca is just too large to be a full dependency, then we'll leave it as a separate installation step). |
Well, I've just tried to create an image by using orca within the python api. However this code doesn't produce any image:
It returns: done with code 1 in 2.59 ms - failed or incomplete task(s) What am I doing wrong here? |
Would you mind opening an issue in the Orca repository? https://github.com/plotly/orca/issues |
Done: plotly/orca#95 |
Done in 3.2.0 🎉 See https://plot.ly/python/static-image-export/ |
it's not done. orca is not working, it times out when saving images and there are several issues about it.
|
hi Canercak, did you find a solution which works to saving image offline ? thanks! |
@FromTravis are you encountering issues? static image export generally works very well using Orca. Some people have trouble installing it but in my experience the vast majority of the time |
Hi Nicolas, well no. I have followed the figure creation from any help welcome ! thxconda install -c plotly plotly-orca All requested packages already installed. error message when calling fig.write_image() : C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py in write_image(fig, file, format, scale, width, height, validate) C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py in to_image(fig, format, width, height, scale, validate) C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py in ensure_server() C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py in validate_executable() ValueError: Searched for executable ‘C:\ProgramData\Anaconda3\orca_app’ on the following path: If you haven’t installed orca yet, you can do so using conda as follows: $ conda install -c plotly plotly-orca Alternatively, see other installation methods in the orca project README at After installation is complete, no further configuration should be needed. If you have installed orca, then for some reason plotly.py was unable to
After updating this executable property, try the export operation again.
If you’re still having trouble, feel free to ask for help on the forums at |
OK, so this error message is saying that the |
Orca cmd is on C:\ProgramData\Anaconda3 and i ve added both to PATH. |
It does work on my Mac though . |
I have uninstalled orca and reinstalled it. (base) C:\Users\P885880\ml>conda install -c plotly plotly-orca psutil requests All requested packages already installed.(base) C:\Users\P123456\ml>where orca When i try to save the image following the plotly orca exemple in jupyter i get:ValueError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\plotly\basedatatypes.py in write_image(self, *args, **kwargs) C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py in write_image(fig, file, format, scale, width, height, validate) C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py in to_image(fig, format, width, height, scale, validate) ValueError: |
Referencing: #596 and #564
For saving an image you have first open it in the browser,
for example in jupyter:
plotly.offline.plot(fig, filename=filename, image='svg')
opens a new tab and download immediately, when adding
auto_open=False
:plotly.offline.plot(fig, filename=filename, image='svg', auto_open=False)
then it will not open a new tab, but it will not download the image as well.
The jupyter command was only an example, of course this functionality would be more useful in text only scripts (python, javascript, R).
The text was updated successfully, but these errors were encountered: