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

Downloading a plotly plot as png in python interactive does not appear to actually save anywhere #3147

Closed
geophpherie opened this issue Sep 5, 2019 · 3 comments
Assignees

Comments

@geophpherie
Copy link

Environment data

  • VS Code version: 1.38.0
  • Extension version (available under the Extensions sidebar): 2019.9.34474
  • OS and version: MacOS 10.14.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.4
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: plotly 4.1.0
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version vscode-python#3977): True

Expected behaviour

After generating a plotly plot in Python Interactive, I want to save/download the plot as a png. I click on the little camera icon to “download plot as a png”. Two small screens appear saying “taking a snapshot, this may take a few seconds” then “Snapshot succeeded - newplot.png”. I would expect that file to then exist in my workspace.

Actual behaviour

The file does not appear in my workspace, and searching on my computer does not show any file existing.

Steps to reproduce:

  1. Generate plotly plot in python interactive window.
import plotly.express as px

iris = px.data.iris()
px.scatter(iris, x="sepal_width", y="sepal_length")
  1. Click download plot as png.
  2. Unable to find said file.

Screen Shot 2019-09-05 at 1 24 35 PM

Logs

Not comfortable dumping those right now because this is my work machine.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 6, 2019

I believe this is a limitation of the webview API of VS Code (which the plotly code is running inside of)

It looks like under the covers plotly is doing this:

if(canUseSaveLink) {
            blob = helpers.createBlob(url, format);
            objectUrl = helpers.createObjectURL(blob);

            saveLink.href = objectUrl;
            saveLink.download = name;
            document.body.appendChild(saveLink);
            saveLink.click();

            document.body.removeChild(saveLink);
            helpers.revokeObjectURL(objectUrl);
            blob = null;

            return resolve(name);
        }

(https://github.com/plotly/plotly.js/blob/7e789b35e9daa5ca8243febe0027d29d402ff772/src/snapshot/filesaver.js#L55)

We might be able to override the 'saveLink' on a document node, not sure.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 6, 2019

SO is saying yes, we can override the link click. Just need to figure out what to do with it:

document.addEventListener('click', event => {
    let node = event && event.target;
    while (node) {
        if (node.tagName && node.tagName === 'A' && node.href) {
            // Handle click here by posting data back to VS Code
            // for your extension to handle
            vscode.postMessage({ ... });
            event.preventDefault();
            return;
        }
        node = node.parentNode;
    }
}, true);``

@DonJayamanne
Copy link
Contributor

Validated

@lock lock bot locked as resolved and limited conversation to collaborators Nov 28, 2019
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants