quarto-ext / shinylive

Quarto extension to embed Shinylive for Python applications
https://quarto-ext.github.io/shinylive/
MIT License
146 stars 8 forks source link

Shinylive-R embedded in Quarto not rendering without R in PATH #64

Open kv9898 opened 3 weeks ago

kv9898 commented 3 weeks ago

I was asked to file it here by the Quarto team (https://github.com/quarto-dev/quarto/issues/557).

System details:

Windows 11 64-bit

Version details:

Positron Version: 2024.09.0 (system setup) build 77 Code - OSS Version: 1.93.0 Date: 2024-09-23T02:44:07.418Z 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

Quarto: 1.6.15 shinylive (R package): 0.2.0

Interpreter details:

R 4.4.1

Describe the issue:

Seems to be a Windows only issue.

In a nutshell, without R in PATH for Windows:

Steps to reproduce the issue:

  1. No R in PATH (default setting for Windows)
  2. Start a new folder for the Quarto project
  3. Open the folder in Positron/VS Code
  4. Execute quarto add quarto-ext/shinylive in Terminal to install the Quarto extension.
  5. Run install.packages("shinylive") if it has not been installed before.
  6. Start a .qmd file
  7. Include the following minimum quarto document, and render:
---
title: "Shinylive R test"
filters:
  - shinylive
---
```{shinylive-r}
#| standalone: true
7. You get an error.

## Expected or desired behavior:

Running normally as in RStudio.
![image](https://github.com/user-attachments/assets/c528598e-96d6-4c59-b161-980ce5991ba3)

From RStudio Background Jobs:

==> quarto preview shinyliver.qmd --to default --no-watch-inputs --no-browse

pandoc to: html output-file: shinyliver.html standalone: true section-divs: true html-math-method: mathjax wrap: none default-image-extension: png

metadata document-css: false link-citations: true date-format: long lang: en title: Shinylive R test

ℹ Loading metadata database ✔ Loading metadata database ... done

Output created: shinyliver.html

Watching files for changes Browse at http://localhost:5239/


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

From Positron/VS Code Terminal:

PS D:\OneDrive - London School of Economics\Desktop\shinyliveRError> quarto preview "d:/OneDrive - London School of Economics/Desktop/shinyliveRError/shinyliver.qmd" --no-browser --no-watch-inputs pandoc to: html output-file: shinyliver.html standalone: true section-divs: true html-math-method: mathjax wrap: none default-image-extension: png

metadata document-css: false link-citations: true date-format: long lang: en title: Shinylive R test

(E) Error running 'Rscript' command. Perhaps you need to install / update the 'shinylive' R package? Error: PandocError {} Error running filter D:/quarto/share/filters/main.lua: ...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:40: Error running 'Rscript' command. Perhaps you need to install / update the 'shinylive' R package?

stack traceback: ...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:40: in global 'throw_quarto_error' ...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:86: in global 'callRShinylive' ...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:113: in global 'callShinylive' ...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:286: in global 'ensureBaseSetup' ...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:315: in global 'ensureLanguageSetup' ...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:424: in function <...iveRError_extensions\quarto-ext\shinylive\shinylive.lua:408>
[C]: in ? [C]: in method 'walk' D:/quarto/share/filters/main.lua:558: in local 'checked_walk' D:/quarto/share/filters/main.lua:610: in function 'run_emulated_filter' D:/quarto/share/filters/main.lua:1335: in local 'callback' [string "..."]:1888: in field 'withScriptFile' D:/quarto/share/filters/main.lua:1351: in upvalue 'run_emulated_filter_chain' D:/quarto/share/filters/main.lua:1389: in function <D:/quarto/share/filters/main.lua:1386> stack traceback: D:/quarto/share/filters/main.lua:558: in local 'checked_walk' D:/quarto/share/filters/main.lua:610: in function 'run_emulated_filter' D:/quarto/share/filters/main.lua:1335: in local 'callback' [string "..."]:1888: in field 'withScriptFile' D:/quarto/share/filters/main.lua:1351: in upvalue 'run_emulated_filter_chain' D:/quarto/share/filters/main.lua:1389: in function <D:/quarto/share/filters/main.lua:1386>



This error is misleading since it tells the user to (re)install the shinylive R package, whereas what the user really needs to to is to put R in PATH/the lua should detect R in other ways.

@jennybc points out in https://github.com/quarto-dev/quarto/issues/557#issuecomment-2388957433 that:
> I can speak to the Positron + Windows part of this. By default, the CRAN R installer for Windows does not put R on the PATH. Therefore R installation discovery focuses on well-known places and learning from the registry instead. Most Windows users will not have R on the PATH, so a naked call to `R` or `Rscript` is going to fail.

@cscheid thinks this leads to a problem (https://github.com/quarto-dev/quarto/issues/557#issuecomment-2389066202) given https://github.com/quarto-ext/shinylive/blob/d93c9f217fd23d44deaabe3ed51b3ba4dc61ba14/_extensions/quarto-ext/shinylive/shinylive.lua#L81
kv9898 commented 3 weeks ago

Strangely, while rendering from the Quarto CLI works fine for both R and Python, in RStudio I got an error of:

Error running 'shinylive' command. Perhaps you need to install / update the 'shinylive' Python package?

Seems that RStudio executes the filter in a different way than the CLI.

A reprex:

---
title: "Shinylive Python test"
filters:
  - shinylive
---
```{shinylive-python}
#| standalone: true
nshobert commented 3 weeks ago

I wonder if this is similar to an issue I'm having. I'm trying to use Python shinylive extension. I've followed similar steps as you have, though I'm using VSCode and Codespaces.

The Quarto site runs, the shinylive editor renders while the viewer loads, but then the viewer can't load and collapses the whole Shinylive block into a gray line. My Edge browser console says:

Uncaught Error: ServiceWorker controller was not found! at setupAppProxyPath (shinylive.js:35071:11)

kv9898 commented 3 weeks ago

Hi there. In my case, the site wouldn't run at all, so I guess you are experiencing a separate problem. Your experience sounds like this issue below, maybe checking that one out is useful!

https://github.com/posit-dev/shinylive/issues/133

nshobert commented 3 weeks ago

kv9898, thank you for the link! Yes, #133 is the issue I'm having. I'm not sure how I missed it when looking in Issues.

Best of luck with your challenge above.

kv9898 commented 3 weeks ago

kv9898, thank you for the link! Yes, #133 is the issue I'm having. I'm not sure how I missed it when looking in Issues.

Best of luck with your challenge above.

You're welcome! There are quite a lot of 'shinylive' repos out there, haha. This repo is for the quarto extension only, while the link I shared with you belongs to the 'main' repo. There are also another 2 'shinylive' repos for the R and Python packages, respectively.

schloerke commented 2 weeks ago

@cscheid Any suggestions on how to call Rscript properly? Thank you in advance!

cscheid commented 2 weeks ago

Quarto does this:

https://github.com/quarto-dev/quarto-cli/blob/740829733499855335a7861e3c4f1333a09db45d/src/core/resources.ts#L84-L171

It strikes me that this is such a complicated dance that Quarto should probably make the result of this call available to Lua filters.

cscheid commented 2 weeks ago

@schloerke

cscheid commented 2 weeks ago

The PR is merged, and the quarto.paths.rscript() API entry point will be available starting in Quarto 1.6.23. (Since your extension will probably have to support Quarto 1.5 for a while, you will need to check for the presence of the quarto.paths table.)

schloerke commented 2 weeks ago

Thank you @cscheid !