posit-dev / positron

Positron, a next-generation data science IDE
Other
1.05k stars 25 forks source link

R: Some htmlwidgets don't work in the Plots pane #2023

Open juliasilge opened 5 months ago

juliasilge commented 5 months ago

In #1742 we worked on adding support for R htmlwidgets in the Plots pane, including getting the needed external libraries. With that initial work, plotly and leaflet work 🎉 but there are some remaining problems. As of Positron 2024.01.0 (Universal) build 30, I see problems with:

library(highcharter)
hchart(mtcars, "scatter", hcaes(wt, mpg, z = drat, color = hp)) 
library(threejs)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3js(x,y,z, color=rainbow(length(z)))

What I observe is that the new plot that gets generated looks empty/blank and there are errors like this:

Screenshot 2024-01-08 at 9 18 28 AM

juliasilge commented 2 months ago

Another one that does not work is ggiraph:

library(ggplot2)
library(ggiraph)
g <- ggplot(mpg, aes(x = displ, y = cty)) +
  geom_point_interactive(
    aes(tooltip = model, data_id = model),
    size = 3, hover_nearest = TRUE
  )

girafe(ggobj = g)

Reported in private beta: https://github.com/posit-dev/positron/issues/2843

juliasilge commented 2 months ago

This issue is also related to https://github.com/posit-dev/positron/issues/2559#issuecomment-2049254813, in that we could consider whether htmlwidgets should go to the Plots pane at all, given that the Viewer pane can have UI affordances like "open the URL in a browser" and an action like "save a plot" has such a different meaning for HTML content.

jmcphers commented 1 month ago

Another is mapview. https://github.com/posit-dev/positron-beta/discussions/182

juliasilge commented 1 month ago

Another is the bslib components htmlwidget support: https://rstudio.github.io/bslib/articles/custom-components/index.html#html-widgets

bslib::page_sidebar()

Reported in our private beta here: https://github.com/posit-dev/positron-beta/discussions/182#discussioncomment-9501885

gadenbuie commented 3 days ago

Some additional feedback that sending html widgets to the Plots pane misses the "open in browser" affordance of the Viewer pane: https://github.com/posit-dev/positron/discussions/3686#discussioncomment-9905639

gadenbuie commented 3 days ago

Also of note, some HTML outputs get sent to the Viewer pane, e.g. gt::gt(mtcars), but don't get the "open in browser" affordance or toolbar. https://github.com/posit-dev/positron/discussions/3686#discussioncomment-9905734

juliasilge commented 21 hours ago

Additional feedback from someone who prefers that htmlwidgets go to the Viewer pane (not Plots): https://github.com/posit-dev/positron/issues/3750