positron icon indicating copy to clipboard operation
positron copied to clipboard

R 'sortable' HTML widgets are not interactive in Positron

Open jmcphers opened this issue 1 year ago • 4 comments

Positron Version:

Positron Version: 2024.01.0 (Universal) build 223
Code - OSS Version: 1.85.0
Commit: 20518f2f1097ce4125c43a3b36b17a854fdbb39a
Date: 2024-01-26T03:12:36.174Z
Electron: 25.9.7
ElectronBuildId: undefined
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.2.0

Steps to reproduce the issue:

Run this R code:

library(sortable)

rank_list(
    text = "You can drag, drop and re-order these items:",
    labels = c("one", "two", "three", "four", "five"),
    input_id = "example_2"
  )

A Sortable widget appears in the Plots pane, but it doesn't work (you can't actually sort anything).

image

What did you expect to happen?

You should get an interactive widget with styling, like RStudio:

image

Were there any error messages in the output or Developer Tools console?

Yes, and they are pretty indicative of the error:

index.js:11     GET vscode-webview://0qpdnnpc99d1857m1q4dnk35r8np48qks1hmmcp95hj9th1dumv1/lib/sortable-rank-list-0.5.0/rank_list.css net::ERR_ACCESS_DENIED
index.js:11     GET vscode-webview://0qpdnnpc99d1857m1q4dnk35r8np48qks1hmmcp95hj9th1dumv1/lib/htmlwidgets-1.6.4/htmlwidgets.js net::ERR_ACCESS_DENIED
...

It looks like the mechanism that allows HTML widget resources to load into the Plots pane isn't work for this widget for some reason.

jmcphers avatar Jan 26 '24 17:01 jmcphers

It looks like this package emits an object that doesn't declare its HTML dependencies in an attribute as we expect. Instead it's a shiny.tag.list, the third element of which is a list of dependencies. I'm sure there's a good way to discover these...

> class(foo)
[1] "rank_list"      "shiny.tag.list" "list"          
> names(foo)
[1] "" "" ""
> foo[[3]]
[[1]]
List of 10
 $ name      : chr "sortable-rank-list"
 $ version   : chr "0.5.0"
 $ src       :List of 1
  ..$ file: chr "htmlwidgets/plugins/sortable-rstudio"
 $ meta      : NULL
 $ script    : chr "rank_list_binding.js"
 $ stylesheet: chr "rank_list.css"
 $ head      : NULL
 $ attachment: NULL
 $ package   : chr "sortable"
 $ all_files : logi TRUE
 - attr(*, "class")= chr "html_dependency"

jmcphers avatar Jan 26 '24 18:01 jmcphers

If you tell me that I need to modify sortable objects as we emit these from the package, I can do that.

What is the format for "HTML dependencies in an attribute as we expect"?

andrie avatar Jan 27 '24 15:01 andrie

If it works in RStudio, we should be able to get it to work in Positron. Positron is calling htmltools::resolveDependencies to try to extract the dependencies, and I believe that's the step that's failing.

https://github.com/posit-dev/amalthea/blob/4fbc62e9df797fe65231a37fdb7545be11d5d4ef/crates/ark/src/modules/positron/html_widgets.R#L9-L14

jmcphers avatar Jan 31 '24 17:01 jmcphers

Should be resolved in #4151.

image

Note that while the widget does render correctly and you can drag, you can't drop. I think this has to do with eventing in the overlay webview; dropping does work if you pop it out into a regular browser.

jmcphers avatar Jul 25 '24 22:07 jmcphers

Verified Fixed

Positron Version(s) : 2024.07.0-107
OS Version          : OSX

Test scenario(s)

library(sortable)

rank_list( text = "You can drag, drop and re-order these items:", labels = c("one", "two", "three", "four", "five"), input_id = "example_2" )

As @jmcphers mentioned, you can drag but not drop unless you pop out to a regular browser.

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

testlabauto avatar Jul 29 '24 14:07 testlabauto