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

Some Python plots only works when executed in console (e.g plotly and altair) #4891

Open
jonvanausdeln opened this issue Oct 3, 2024 · 6 comments
Labels
lang: python testing Unit, extension-level, and smoke tests

Comments

@jonvanausdeln
Copy link
Contributor

System details:

Windows 11
Ubuntu 22

Positron and OS details:

2024.10.0-13

Interpreter details:

Python 3.12.2

Describe the issue:

Running the following code using the play button "Run Python File in Console" results in an error, but running line by line in the console works.

Steps to reproduce the issue:

import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig

Image

Expected or desired behavior:

Figure to show when clicking the run button as well as line by line in the console.

Were there any error messages in the UI, Output panel, or Developer Tools console?

@juliasilge juliasilge added the testing Unit, extension-level, and smoke tests label Oct 7, 2024
@juliasilge juliasilge added this to the 2024.11.0 Pre-Release milestone Oct 7, 2024
@seeM
Copy link
Contributor

seeM commented Oct 8, 2024

I think part of this is just how Python works. Since the script is named plotly, when you do import plotly.express it's actually importing the script and failing because it's not a package.

You can fix that issue by renaming the module to something other than plotly.py.

After that fix, it still doesn't display anything in the plots pane for me though.

@jonvanausdeln
Copy link
Contributor Author

@seeM , yes I'm going to go through our example codebase and make sure to fix this and any other with similar filenames.

@testlabauto
Copy link
Contributor

I think we mistakenly assigned this to you, @jonvanausdeln. As @seeM mentioned, even after the rename there is an issue.

@jonvanausdeln
Copy link
Contributor Author

I think we mistakenly assigned this to you, @jonvanausdeln. As @seeM mentioned, even after the rename there is an issue.

I think you are correct. I will move it back to backlog and remove my name. I will still fix the filenames (and tests that use them). But I just checked and yes, it still won't run with the filename changed.

@jonvanausdeln jonvanausdeln removed their assignment Oct 9, 2024
@testlabauto
Copy link
Contributor

Also note that plotly doesn't work in a notebook:

{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "library(plotly)\n",
        "# install.packages('mvtnorm')\n",
        "\n",
        "# change this to scale up or down per cell\n",
        "# 500,000 will create about a 77 Mb notebook on disk\n",
        "data_size = 500000\n",
        "\n",
        "s <- matrix(c(1, -.75, -.75, 1), ncol = 2)\n",
        "obs <- mvtnorm::rmvnorm(data_size, sigma = s)\n",
        "\n",
        "fig <- plot_ly(x = obs[,1], y = obs[,2])\n",
        "fig2 <- subplot(\n",
        "  fig %>% add_markers(alpha = 0.2),\n",
        "  fig %>% add_histogram2d()\n",
        ")\n",
        "\n",
        "fig2"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3",
      "path": "/usr/local/share/jupyter/kernels/python3"
    },
    "language_info": {
      "name": "r"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}

@jonvanausdeln
Copy link
Contributor Author

An altair plot also does not show in the plots pane when run from a file. E.g. code found here

But does show if executed line-by-line using ctrl+enter

@jonvanausdeln jonvanausdeln changed the title Python plotly only works when executed in console Some Python plots only works when executed in console (e.g plotly and altair) Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: python testing Unit, extension-level, and smoke tests
Projects
None yet
Development

No branches or pull requests

4 participants