posit-dev / positron

Positron, a next-generation data science IDE
Other
2.5k stars 77 forks source link

Polygot Quarto document doesn't store python plots in plot pane & prompts for a new reticulate default env instead of using existing #3865

Open coatless opened 3 months ago

coatless commented 3 months ago

Positron Version:

Positron Version: 2024.06.1 (Universal) build 54 Code - OSS Version: 1.90.0 Commit: 5115c73e0670f39139e55eeedf0717b468a0658d Date: 2024-07-03T03:51:33.756Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.5.0

Steps to reproduce the issue:

  1. Create a new Quarto Document in a Positron session with both a Python environment & R environment activate
  2. Inside the Quarto document, place:
---
format: html
---

```{r}
plot(1:4, ylab = "some numbers")
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()


3. Run each chunk individually. 
4. The Python chunk creates a pop-up window under Ark.

## What did you expect to happen?

I expected:

1. the plot window to catch 
2. reticulate plugin to default to the active python environment without needing to setup a default python environment

Unexpected plot pop-up: 

<img width="1611" alt="Screenshot of the Positron IDE with 2 different code blocks run one R and one Python causing a popup" src="https://github.com/posit-dev/positron/assets/833642/61c66f68-0e4d-4ba5-beab-580bf340d81c">

Expected plot history: 

<img width="768" alt="Screenshot 2024-07-03 at 9 14 14 PM" src="https://github.com/posit-dev/positron/assets/833642/df67c9e6-75a6-4247-8fb7-99e8e2e89219">

## Were there any error messages in the output or Developer Tools console?

N/A
juliasilge commented 3 months ago

Wow, interesting 👀

Can you say more about how you triggered that call to reticulate::repl_python()? I can't figure out how to get that to happen.

If I have a polyglot .qmd and I use, say, Cmd+Shift+Enter to send lines of code to the console for execution, I see the code execute in the correct console (R in the R console, Python in the Python console) and both plots in the Plots pane:

polyglot

coatless commented 3 months ago

A few videos:

When saved in a project:

https://github.com/posit-dev/positron/assets/833642/a21ee67b-99f0-432f-bc18-18b39b1d621b

Empty/untitled document (this sometimes won't render when saying reticulate environment has "no")

https://github.com/posit-dev/positron/assets/833642/f78d3b52-7f8e-4a9f-a88c-93a387dd09bd

I suppose another question is: what environment is reticulate using if its not detecting the default being available?

juliasilge commented 3 months ago

Ah, you were clicking the "Run Cell" button! I believe this will take a PR to the Quarto extension sort of along these lines to fix: https://github.com/quarto-dev/quarto/pull/436 We'll need to navigate whether to go through reticulate at all for interactive code execution. (Rendering the document will of course have to go through reticulate.) Related to the second bullet in https://github.com/posit-dev/positron/issues/1646#issuecomment-2135993785.

As a short term workaround, you can use use Cmd+Shift+Enter to send lines of code to the console for execution, although for Python then you are running into the first bullet at https://github.com/posit-dev/positron/issues/1646#issuecomment-2135993785.

Please do add anything to that other issue that you think is relevant. We'll keep this one open as a specific case to check when we make changes to the Quarto extension.

coatless commented 3 months ago

@juliasilge role-playing the student and newly minted DS analyst with a button > keyboard shortcut mindset.