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

Table previews don't appear in Positron #298

Closed
andrewheiss opened this issue Jul 4, 2024 · 4 comments
Closed

Table previews don't appear in Positron #298

andrewheiss opened this issue Jul 4, 2024 · 4 comments

Comments

@andrewheiss
Copy link

andrewheiss commented Jul 4, 2024

The first Positron-related issue!

In Positron (but not VS Code, weirdly), {tinytable} tables don't appear in the preview window and instead cause an error:

Error:
! Function viewer not found in RStudio
Hide Traceback
    ▆
 1. ├─methods (local) `<stndrdGn>`(`<tinytabl[,5]>`)
 2. └─tinytable (local) `<stndrdGn>`(`<tinytabl[,5]>`)
 3.   └─tinytable:::print.tinytable(...)
 4.     └─rstudioapi::viewer(htmlFile)
 5.       └─rstudioapi::callFun("viewer", url, height = height)

Here's a reprex:

This works

```{r}
library(gt)

mtcars[1:5, 1:5] |>
  gt()
```

This doesn't :(

```{r}
library(tinytable)

mtcars[1:5, 1:5] |>
  tt()
```
image

 

It seems like print.tinytable() is trying to use rstudioapi::viewer() inside Positron? In VS Code, print.tinytable() doesn't try to use {rstudioapi} and instead shows the table in the Viewer tab, as expected:

image
@vincentarelbundock
Copy link
Owner

Interesting. There seem to be two issues.

rstudioapi incorrectly detects RStudio when running in Positron

I believe this is a straightforward bug, and I have reported it upstream here: rstudio/rstudioapi#302

Until this gets fixed, I implemented error catching when trying to opening the RStudio viewer in a different IDE. If this fails, print.tinytable() will keep going and launch a browser.

In VSCode, launching this kind of browser usually embeds the HTML in a dedicated pane inside the IDE. (Assuming you have some kind of local server extension installed.)

In Positron, this seems to launch a separate browser window (on my machine).

Equivalent of rstudioapi::viewer() is not implemented for Positron.

This is a known issue, and I hope the Positron team will offer this feature, because it feels quite important to me. Here's the ticket:

posit-dev/positron#2559

What does gt do?

I have no idea. Would be very interested in learning about their solution!

@kylebutts
Copy link
Contributor

kylebutts commented Jul 5, 2024

@vincentarelbundock Both VSCode and Positron expose options("viewer")$viewer which accepts a url for html. In fact, gt uses htmltools::html_print which uses viewer = getOption("viewer", utils::browseURL)

Edit: RStudio has this too: https://github.com/rstudio/rstudio/blob/d2713874570f06dccc92a46d15e5939922817c7b/src/cpp/r/R/Options.R#L29

@vincentarelbundock
Copy link
Owner

Thanks for the suggestion @kylebutts . I'll look into that when I find some time.

Note: Posit recommends rstudioapi::hasFun("viewer")

rstudio/rstudioapi#302 (comment)

@vincentarelbundock
Copy link
Owner

@andrewheiss , FYI, @kylebutts is a superstar and just fixed this for us. His PR is merged and tiny tables appear as expected in the Viewer Pane in my local Positron.

Yay!

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

3 participants