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

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

Open
kv9898 opened this issue Oct 2, 2024 · 10 comments
Open

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

kv9898 opened this issue Oct 2, 2024 · 10 comments

Comments

@kv9898
Copy link

kv9898 commented Oct 2, 2024

I was asked to file it here by the Quarto team (quarto-dev/quarto#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:

  • Positron/VS Code + Quarto + Shinylive + R = ×
  • Positron/VS Code + Quarto + Shinylive + Python = √
  • RStudio + Quarto + Shinylive + R = √
  • Positron/VS Code + Shiny + R = √

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

```
  1. You get an error.

Expected or desired behavior:

Running normally as in RStudio.
image

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 quarto-dev/quarto#557 (comment) 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 (quarto-dev/quarto#557 (comment)) given

res = pandoc.pipe("Rscript", args, input)

@kv9898
Copy link
Author

kv9898 commented Oct 2, 2024

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
Copy link

nshobert commented Oct 5, 2024

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
Copy link
Author

kv9898 commented Oct 5, 2024

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!

posit-dev/shinylive#133

@nshobert
Copy link

nshobert commented Oct 5, 2024

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
Copy link
Author

kv9898 commented Oct 5, 2024

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
Copy link
Collaborator

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

@cscheid
Copy link

cscheid commented Oct 7, 2024

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
Copy link

cscheid commented Oct 7, 2024

@schloerke

@cscheid
Copy link

cscheid commented Oct 7, 2024

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
Copy link
Collaborator

Thank you @cscheid !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants