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

Mapping packages do not show any output (geemap, mapview, leaflet ...) #4057

Closed
Cidree opened this issue Jul 17, 2024 · 5 comments
Closed

Mapping packages do not show any output (geemap, mapview, leaflet ...) #4057

Cidree opened this issue Jul 17, 2024 · 5 comments
Labels
area: plots Issues related to Plots category. area: widgets Issues related to Widgets. bug Something isn't working lang: python lang: r support

Comments

@Cidree
Copy link

Cidree commented Jul 17, 2024

Positron Version: 1.91.0

b189a8b
x64

Steps to reproduce the issue:

import ee
import geemap

ee.Initialize()

m = geemap.Map()
m

What did you expect to happen?

To display a map.

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

There are no error messages. When I execute the previous code, I got this result in the console:

>>> m
Map(center=[0, 0], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=SearchDataGUI(childr…

But no map is shown in the plots or viewer panes. I have similar issues with several R packaes:

mapview and leaflet

The following code:

library(mapview)
mapview()

library(leaflet)
leaflet()

Displays a white window in the plots panel, and the following output in the console:

> mapview(aa)
<R HTML Widget>

> leaflet()
<leaflet HTML widget>
@Cidree Cidree added the bug Something isn't working label Jul 17, 2024
@juliasilge
Copy link
Contributor

For me, I see this code behaving the same way in RStudio and Positron:

library(leaflet)
leaflet()

In the mapview example, we are not correctly loading HTML dependencies into the Plots pane and there are errors in the Developer Tools console about not loading leaflet providers with net::ERR_ACCESS_DENIED.

Related to #3756, #3968, and #2023

@jmcphers
Copy link
Collaborator

mapview should work now, after #4151:

image

The Python issue is probably separate.

jmcphers added a commit that referenced this issue Jul 26, 2024
This change holistically addresses a large number of issues around
viewing R HTML widgets, and HTML in general, in the Viewer and Plots
panes. Specifically, it addresses the following issues:

#2023
#2145
#2559
#2888
#3018
#3678
#3756
#3783
#3914
#3968
#4057

Prior to this change, R HTML widgets were emitted from Ark as notebook
outputs in format compatible with the [VS Code Notebook Renderer
API](https://code.visualstudio.com/api/extension-guides/notebook#notebook-renderer).
This approach was chosen because we need to be able to render these
kinds of outputs in any case (other kernels emit them), and for minimal
friction with the existing infrastructure.

However, R HTML widgets aren't really a good match for Notebook Renderer
API, and the abstraction was very leaky. In particular, the API is
really designed to be used by widgets directly -- for example, plotly
has an output renderer -- not as a layer on top of another widget
framework. It also can't be used to just render HTML output directly,
which is what a lot of R code does.

The approach taken here largely supersedes the notebook output approach
(for console sessions). It extends our existing help proxy with a new
file proxy. R HTML content is rendered to a temporary path on disk, and
then we create a proxy that serves content from the path on disk.

```mermaid
graph TD
proxy[Positron Proxy] --HTML --> pos[Positron]
html[(HTML)] -- read by--> proxy
pos -- create proxy --> proxy
R(R runtime) -- generates --> html
R -- show_html_file UI comm --> pos
```

Step by step:

1. An HTML widget is emitted in R.
2. Ark's custom HTML widget printer is invoked.
3. Ark renders the widget to a temporary directory, using `html_print`. 
4. Ark emits a `show_html_file` event over the UI comm to Positron with
the path to the rendered widget.
5. Positron receives the `show_html_file` event.
6. Positron asks the Positron Proxy extension to create a server URL for
the file path.
7. The Positron Proxy extension uses an Express server to create a route
that serves the static content at a random URL.
8. The Positron Proxy extension sends the URL back to Positron.
9. Positron opens the URL in the Viewer or Plots pane, as appropriate.

### New Features 

In addition to fixing some bugs around HTML rendering, we have a few new
features enabled by this approach:

#### Popout Interactive Content

Because we now have a real URL for HTML content, it can be opened in web
browsers. Plots that are based on HTML content now have a popout
affordance:


![image](https://github.com/user-attachments/assets/67fda7d4-ddb0-46f3-b182-37bb698f76cf)

And so does HTML content rendered into the Viewer pane:


![image](https://github.com/user-attachments/assets/5271401d-822d-4f0a-b7ab-e9ebc94821f6)

#### For the Plots Pane haters

Don't like HTML going to your Plots pane? You can turn it off, so all
HTML content goes to the Viewer pane.

<img width="550" alt="image"
src="https://github.com/user-attachments/assets/30a2c79f-66ba-4924-b6f7-83b7367108b0">

*Why would you want to live this way, though?*

#### RStudio Viewer API

The `rstudio::viewer()` API is implemented with this change, so R
packages that depend on it to show content will work correctly.

#### Open in Viewer context menu

You can now open HTML files directly in the Viewer pane using a context
menu action in the Explorer pane:

<img width="422" alt="image"
src="https://github.com/user-attachments/assets/0e269f6a-02fb-4384-94a5-5396f23cde44">

### QA Notes

Here's a bunch of test cases. These are all things that didn't work
before this PR.

#### Mapview

Opens up a nice map in the Viewer pane. 

```r
library(mapview)
m <- mapview()
m
```

### ggiraph

An interactive 2D plot. Should open up in the Plots pane.


```r
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)
```

#### Threejs

An interactive 3D plot. Should open up in the Plots pane.

```r
library(threejs)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3js(x,y,z, color=rainbow(length(z)))
```

#### Model Summary

This is one of those packages that calls `rstudioapi::viewer` directly. 

```r
library(palmerpenguins)
library(fixest)
library(modelsummary)
m1 = feols(body_mass_g ~ bill_depth_mm + bill_length_mm | species, data = penguins)
modelsummary(m1)
```

#### React Table

Also should open in the Viewer.

```
library(reactable)
mtcars |> reactable::reactable()
```

#### Reprex

A common R package used to create reproducible examples. Should open in
the Viewer.

```r
reprex::reprex({
  x <- rnorm(100)
  plot(x, sin(x))  
})
```

### Impacted Areas

This change touches code outside R HTML widgets, so these code paths
should also be spot checked for issues.

- Previewing URLs in the Viewer (e.g. Streamlit, Shiny content)
- Previewing extension-provided content in the Viewer (e.g. Quarto)
- Notebook outputs in the Plots pane (e.g. IPyWidgets)
@Cidree
Copy link
Author

Cidree commented Jul 27, 2024

That's great to hear @jmcphers !
Shall we close this issue, or keep it with the Python geemap issue?

@juliasilge
Copy link
Contributor

@Cidree can you create a Python mapping example that doesn't use Google Cloud Earth Engine? We aren't set up to use that proprietary service. Please do feel free to open a followup issue with that!

@testlabauto
Copy link
Contributor

Verified Fixed

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

Test scenario(s)

library(mapview)
mapview()

  • then scrolling around/zooming in mapview

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: plots Issues related to Plots category. area: widgets Issues related to Widgets. bug Something isn't working lang: python lang: r support
Projects
None yet
Development

No branches or pull requests

6 participants