positron icon indicating copy to clipboard operation
positron copied to clipboard

Python (reticulate) variables pane not updating after changes from R

Open kv9898 opened this issue 1 year ago • 4 comments

System details:

Windows 11

Positron and OS details:

Positron Version: 2024.09.0 (system setup) build 103 Code - OSS Version: 1.93.0 Commit: 8274fe26a1582fa0dd0096d6631b500f591416c4 Date: 2024-09-30T02:46:12.087Z Electron: 30.4.0 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.22631

Interpreter details:

R 4.4.1 Python(Venv: r-reticulate): 3.11.4

Describe the issue:

When Python (reticulate) variables are updated from the R end, the variable pane is not updated, even when a different variable is updated through the Python console.

Steps to reproduce the issue:

  1. Run reticulate::py_run_string("a=1") in R console
  2. Switch to the Python (reticulate) interpreter
  3. No variable is displayed in the pane.
  4. Run print(a) in the Python console
  5. The correct value 1 is printed, but the variable pane is not updated.
  6. Run b=1 in the Python console
  7. variable b is displayed in pane, but a is still not shown.

Expected or desired behavior:

Variable panes are updated whenever there is a change in the interpreter

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

None

kv9898 avatar Oct 02 '24 05:10 kv9898

As a sidenote, I found that after I enabled the "reticulate" functionality of Positron, Positron initiates the reticulate environment when it boots. This is a bit problematic if I want to choose a different environment (I have to start R). Is this worth opening a separate issue?

This is opened as a separate issue in https://github.com/posit-dev/positron/issues/4870.

kv9898 avatar Oct 02 '24 06:10 kv9898

Hi @kv9898 ! Thanks for trying it out and for the bug report. I think it's worth opening a separate issue with more details and what behavior you'd have expected.

I'd also love to listen to your overall thoughts and impressions on the reticulate feature. Even if not directly actionable items. Thank you!

dfalbel avatar Oct 02 '24 10:10 dfalbel

Hi @kv9898 ! Thanks for trying it out and for the bug report. I think it's worth opening a separate issue with more details and what behavior you'd have expected.

I'd also love to listen to your overall thoughts and impressions on the reticulate feature. Even if not directly actionable items. Thank you!

Sure, I will open another issue shortly after more experiments to get things clearer.

In terms of the overall impression, I agree with https://github.com/posit-dev/positron/discussions/3920#discussioncomment-10577036 that this is a "killer functionality". I was even so desperate to try it out that I couldn't wait for the pre-release build and even forked the Positron repo and try to build from the workflow (I failed, probably because I'm a noob to github workflows).

Sadly, as a Political Science student, there aren't a lot of multilingual opportunities for myself. The only use case for my so far is running TensorFlow/Keras in R, as it is a wrapper for Python. In this case it is helpful to use the reticulate Python interface for debugging, etc.

Ironically, my main issue with using reticulate in Python was that the output was not shown on Windows (#4580). I didn't expect a quick solution since that issue was added to the Future milestone and the reticulate support feature came as (in a positive sense) an overkill. It's good news for me that I can go to the Python console to see what's been printed :)

Finally, I want to say that I love the Positron team for my past interactions with you. I can always expect response to my issue within one working day, which doesn't hold for many other projects. I have actually been using Positron as my main IDE and recommending it to my friend. Weirdly enough, I kinda feel like I'm entrapped by the Posit ecosystem (Positron, shiny, tidyverse, Quarto) even though I've been trying to become bilingual in both R and Python. This company just weirdly covers all of my data science workflows haha.

kv9898 avatar Oct 02 '24 11:10 kv9898

One way to address this issue would be to add a frontend callback that refreshes the Python Variables Pane each time focus shifts (back) the Python Variables Pane. For example, we could execute a Python snippet like this:

__import__("positron_ipykernel.positron_ipykernel").PositronIPyKernel.instance().variables_service.send_refresh_event()

t-kalinowski avatar Oct 09 '24 13:10 t-kalinowski

Verified Fixed

Positron Version(s) : 2024.11.0-103
OS Version          : OSX

Test scenario(s)

remotes::install_github("rstudio/reticulate")

R: reticulate::py_run_string("a=1")

Switch to reticulate: print(a)

Link(s) to TestRail test cases run or created:

testlabauto avatar Oct 24 '24 14:10 testlabauto