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

Quarto R ojs_define function and OJS in RStudio #1242

Open
novotny1akub opened this issue Jun 29, 2022 · 21 comments
Open

Quarto R ojs_define function and OJS in RStudio #1242

novotny1akub opened this issue Jun 29, 2022 · 21 comments
Assignees
Labels
enhancement New feature or request ojs-engine Issues with the ojs engine
Milestone

Comments

@novotny1akub
Copy link

I tried to use Quarto to do data preprocessing in R and then make the created data available in OJS using RStudio, but it seems to me that the ojs_define function is not available. This article suggests that it might be possible, but it does not seem to be working for me.

{r}
#| output: false
ojs_define(mtcars = mtcars)

In addition, it seems that using ojs from RStudio does not seem to be possible either. For example, following results in an error:

{ojs}
viewof bill_length_min = Inputs.range(
  [32, 50], 
  {value: 35, step: 1, label: "Bill length (min):"}
)

Is there a way to do what I tried above or will it be possible eventually?

@jjallaire jjallaire transferred this issue from quarto-dev/quarto-web Jun 29, 2022
@jjallaire
Copy link
Collaborator

ojs doesn’t currently work interactively within RStudio (you have to do a complete render). This will be improved in the future!

@novotny1akub
Copy link
Author

Thanks a lot. Using some features of OJS (e.g. Inputs.range) is working with the complete render now, but when I try to define data in R, and then use it with OJS, it gives me OJS Runtime Error invalid module. In fact even with OJS defined data, it does not seem to be working. The following code gives OJS Runtime Error invalid module.

d3 = require('d3')

contributors = await d3.json(
  "https://api.github.com/repos/pandas-dev/pandas/stats/contributors"
)

commits = contributors.map(contributor => {
  const author = contributor.author;
  return {
    name: author.login,
    title: author.login,
    group: author.type,
    value: contributor.total
  }
})

@cscheid
Copy link
Collaborator

cscheid commented Jun 29, 2022

I can't reproduce this locally on the latest Quarto version. Can you make sure you're running an up-to-date version?

image

@cscheid cscheid self-assigned this Jun 29, 2022
@cscheid cscheid added needs-repro Issues that are blocked until reporter provides an adequate reproduction ojs-engine Issues with the ojs engine labels Jun 29, 2022
@novotny1akub
Copy link
Author

After updating my version, it seems to be working. Sorry for the confusion and thanks.

@novotny1akub
Copy link
Author

novotny1akub commented Jun 29, 2022

I am sorry, but I have to reopen the issue. Below is a reprex. I can successfully define df in R. I can use the df in OJS, but I can't use the Plot module in RStudio. Is there a way to do that?

---
title: "OJS"
format: html
editor: visual
---

```{r}
df <- data.frame(
  year = 1961:1990,
  max = runif(30, -10, 20) |> cumsum()
  )

ojs_define(df = df)
```

```{ojs}
Inputs.table(transpose(df), { sort: "year", reverse: true })
```

```{ojs}
Plot.plot({
  marks: [
    Plot.line(transpose(df), {x: "year", y: "max"})
  ]
})
```

@novotny1akub novotny1akub reopened this Jun 29, 2022
@cscheid
Copy link
Collaborator

cscheid commented Jun 29, 2022

Unfortunately, like jjallaire said, OJS plots in the "Plots" tab are not currently supported in RStudio.

I will note, though, that you can still render the entire document to get this:

image

@cscheid cscheid closed this as completed Jun 29, 2022
@cscheid cscheid reopened this Jun 29, 2022
@cscheid cscheid added this to the Future milestone Jun 29, 2022
@novotny1akub
Copy link
Author

novotny1akub commented Jun 29, 2022

I can't render the plot when rendering the whole document. Here is what I see in the Viewer tab.

image

@cscheid
Copy link
Collaborator

cscheid commented Jun 29, 2022

My guess is you are likely running an older version of RStudio. Try using one of the dailies, perhaps?

@cscheid cscheid closed this as completed Jun 29, 2022
@cscheid cscheid reopened this Jun 29, 2022
@novotny1akub
Copy link
Author

novotny1akub commented Jun 29, 2022

I tried to use the preview version of RStudio, but it does not seem to be working. Please note that the version that I am using, which is working, is the most recent one (non-preview).
image

@novotny1akub
Copy link
Author

novotny1akub commented Jun 30, 2022

I noticed something that seems slightly odd to me - the plot does not display in RStudio's Viewer panel, but when I click on the "Show in new window" button (a part of the Viewer panel), it opens a browser where the plot is displayed with no issues. In addition, I have done some experiments with d3, and it works with no problems even i RStudio Viewer panel.

@cscheid
Copy link
Collaborator

cscheid commented Jun 30, 2022

Ok, I see the issue. When using OJS, it's likely that you will run into modules that use modern JS syntax (such as the nullish coalescing operator ??). These are unfortunately not available in the QtWebEngine version of RStudio, which uses a quite-old version of Chromium.

Can you try using the Electron dailies instead? They're at the rightmost column of https://dailies.rstudio.com/

@novotny1akub
Copy link
Author

Thanks for the explanation, now I get it. I am afraid neither the Electron version is working.

R Session Startup Failure Report

RStudio Version

RStudio 2022.07.0+547 "Spotted Wakerobin " (ec7dc45b, 2022-06-30) for Windows

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2022.07.0+547 Chrome/102.0.5005.63 Electron/19.0.4 Safari/537.36

Error message

[No error available]

Process Output

The R session exited with code 1.

Error output:

[17564:19308:20220630,235631.501:ERROR crashpad_client_win.cc:491] CreateProcess: The system cannot find the file specified. (2)

Standard output:

[No output emitted]

Logs

C:/Users/novot/AppData/Local/RStudio/log/rsession-novot.log

2022-06-30T21:56:31.502192Z [rsession-novot] ERROR system error 22 (The device does not recognize the command); OCCURRED AT class rstudio::core::Error __cdecl rstudio::core::crash_handler::initialize(enum rstudio::core::crash_handler::ProgramMode) src/cpp/core/CrashHandler.cpp:358; LOGGED FROM: int __cdecl main(int,char *const []) C:\Users\jenkins\workspace\ide\open-source-pipeline\spotted-wakerobin\src\cpp\session\SessionMain.cpp:2007
2022-06-30T21:56:31.507184Z [rsession-novot] ERROR system error 22 (The device does not recognize the command); OCCURRED AT class rstudio::core::Error __cdecl rstudio::core::crash_handler::initialize(enum rstudio::core::crash_handler::ProgramMode) src/cpp/core/CrashHandler.cpp:358; LOGGED FROM: int __cdecl main(int,char *const []) C:\Users\jenkins\workspace\ide\open-source-pipeline\spotted-wakerobin\src\cpp\session\SessionMain.cpp:2057
2022-06-30T21:56:31.507184Z [rsession-novot] ERROR system error 22 (The device does not recognize the command); OCCURRED AT class rstudio::core::Error __cdecl rstudio::core::crash_handler::initialize(enum rstudio::core::crash_handler::ProgramMode) src/cpp/core/CrashHandler.cpp:358; LOGGED FROM: int __cdecl main(int,char *const []) C:\Users\jenkins\workspace\ide\open-source-pipeline\spotted-wakerobin\src\cpp\session\SessionMain.cpp:2057

@cscheid
Copy link
Collaborator

cscheid commented Jun 30, 2022

I've contacted the IDE devs and will report back.

@elbert5770
Copy link

Yes, I get the exact same behavior with the Quarto penguins example, almost two months later. RStudio 2022.07.1 Build 554, Windows 11. The issue is with the reactive plot in the Viewer with a rendered document. As noted above, it works fine in a browser (Microsoft Edge) after "Show in new window". A fresh install of RStudio on Linux gives the same error as on Windows. However, the viewer in Visual Studio Code works fine with both jupyter and r engines.

A reactive table works perfectly in the RStudio Viewer , so the problem is localized to the reactive plot in RStudio Viewer.

Thus, the penguins example in the Quarto docs will still fail for many users due to this issue. Another problem that is noted in a separate previous issue is that the example uses an altered version of the penguins.csv, but there is no link to download the custom file. This still has not been resolved, and the Quarto docs haven't been updated to reflect these known issues.

@cscheid
Copy link
Collaborator

cscheid commented Aug 24, 2022

@elbert5770 I'm sorry you hit this issue too. This is a combination of Observable JS source (which we don't control) and RStudio IDE (which has a different release schedule), and as a result it's outside the control of the quarto project. Please report this as an RStudio IDE bug at https://github.com/rstudio/rstudio.

@novotny1akub
Copy link
Author

Can Quarto users somehow recommend to the Quarto team what to add to the documentation? Also, I fell like it would be best to close this issue and open a new one since my initial description is chaotic, which may confuse other users that encounter the issues mentioned above.

@nvelden
Copy link

nvelden commented Oct 13, 2022

I have the same problem. I downloaded the latest version of Rstudio, Quarto and R but I also get the Error in ojs_define(x) : could not find function "ojs_define". Same error occurs in VS code.

---
title: "Untitled"
format: html
editor: visual
---

```{r}
#| echo: false
x = 2 * 2
ojs_define(x)
```

Error in ojs_define(x) : could not find function "ojs_define"`

Session.info:

R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.1  tools_4.2.1     rstudioapi_0.14 knitr_1.40      xfun_0.33      

@jjallaire
Copy link
Collaborator

That function won't work if you execute it as part of just a cell (as it's only available during a render). This is a limitation we definitely hope to overcome at some point but for now that's the deal.

@mcanouil

This comment was marked as off-topic.

@mcanouil mcanouil added the stale Issues open for 30+ days without providing a "working" reproducible example label Jun 12, 2023
@jjallaire
Copy link
Collaborator

@mcanouil this is also not stale as it's a feature request. Let's re-open and remove the stale tag

@mcanouil
Copy link
Collaborator

mcanouil commented Jun 12, 2023

Agreed!
This issue should not have the "needs-repro", thus the "stale" label.
Removing both now.
(Note, that I inadvertently added the stale message/label myself when reviewing all "needs-repro" issues.)

Also adding the "enhancement" label which is the proper label for feature requests.

@mcanouil mcanouil added enhancement New feature or request and removed needs-repro Issues that are blocked until reporter provides an adequate reproduction stale Issues open for 30+ days without providing a "working" reproducible example labels Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ojs-engine Issues with the ojs engine
Projects
None yet
Development

No branches or pull requests

6 participants