ipyleaflet does not render layers on jupyter lab - jupyter-notebook

I've installed ipyleaflet in jupyter lab using based on the following guide: https://ipyleaflet.readthedocs.io/en/latest/installation/index.html#jupyterlab-extension
The following code executes, the map is shown correctly but the layers (in this case one Marker) are not showing up.
from ipyleaflet import Map, Marker
center = [21.501558, 39.184964]
m = Map(center=center, zoom=15)
marker = Marker(location=center, draggable=True)
m.add_layer(marker)
display(m)
The browser console shows the following warnings:
Failed to fetch ipywidgets through the "jupyter.widget.control" comm channel, fallback to fetching individual model state. Reason: Control comm was closed too early
_loadFromKernel
Could not create a view for model id ...
Followed by an error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_layerAdd')
at e.addLayer (leaflet-src.js:6889:16)
at 138.69ef2a39232f5de9d78a.js?v=69ef2a39232f5de9d78a:1:39625
at async Promise.all (index 1)
What could be the reason for layers not showing up on the correctly rendered map?

Related

WebviewPanel: FAILED posting webview/editors/didChangeVisible to the webview

I have graph output in the R/Radian console and in Jupyter, Jupyterlab, and VS Code notebooks. I also get the Rplots.pdf sent to the working directory as expected. However, I don't get embedded "pop-up" graph output when running R scripts in the VS Code editor e.g. filename.R. I always get this error message from CodeStream.
WebviewPanel: FAILED posting webview/editors/didChangeVisible to the webview; Webview is invisible and can't receive messages.
I've read a few SO questions on the Webviews, but they seem to be related to web/JSON loading issues and not R plots.
Seems I am missing a setting or package that pushes the Webview out.
Example code block if needed.
data("mtcars")
cars <- mtcars
print(nrow(cars))
print(head(cars, 10))
x <- c(0:10)
plot(x, sin(x))

Obtaining Metadata Information using ee_print function from RGEE

I am using the package RGEE (R wrapper for the Google Earth Engine Python API). The function ee_print() seems to work perfectly for an ImageCollection of just one variable, but seems to fail for ImageCollection with different variables where one needs to select the variable of interest. Any ideas on how to approach this issues with the latter kind of data.
Here's an example code:
GRIDMET = ee$ImageCollection("IDAHO_EPSCOR/GRIDMET")
ee_print(GRIDMET)
Where I get the following error message in return:
Error in strsplit(code, ":") : non-character argument
Have you considered the following approach?
GRIDMET = ee$ImageCollection("IDAHO_EPSCOR/GRIDMET")
print(GRIDMET, type = getOption("rgee.print.option"))
And play with the list of all metadata properties
GRIDMET$propertyNames()$getInfo()# Get a list of all metadata properties
(GRIDMET$get("product_tags")$getInfo()) # you can choose to show a characteristic like "product_tags"

How to get mapbox style openmap with API key?

I'm trying to make a map in R using OpenStreetMap library.
I had no problem using types such as osm, stamen-toner, stamen-terrain and stamen-watercolor, for instance:
map <- openproj(openmap(c(63.47,10.32),c(63.37,10.54),type='osm'),proj=CRS('+init=epsg:32632'))
par(mar=c(0,0,0,0))
plot(map)
works just fine:
I'll add the points over that layer. However, my client wants a map-box type, but when I run
map <- openproj(openmap(c(63.47,10.32),c(63.37,10.54),type='mapbox'),proj=CRS('+init=epsg:32632'))
I get the following error:
failed loading 12/2165/1106 Server returned HTTP response code: 401 for URL: http://api.tiles.mapbox.com/v4/examples.map-zr0njcqy/12/2165/1106.png?access_token=pk.eyJ1IjoidGhlZmVsbCIsImEiOiJjaXN1anNwODEwMWlrMnRvZHBhamRrZjlqIn0.Gf8qLSpZ6yo5yfQhEutFfQ
java.lang.NullPointerException
at edu.cens.spatial.RTileController.getTileValues(RTileController.java:109)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at RJavaTools.invokeMethod(RJavaTools.java:386)
Error in osmtile(x%%nX, y, zoom, type) :
could not obtain tile: 2165 1106 12
I know I need an API key. I've created one at MapBox site. But now, how do I get a map of map-box type? The examples given are like
apiKey <- paste0('?access_token=','{my key}')
baseUrl <- 'https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v9/tiles/256/{z}/{x}/{y}'
map <- openproj(openmap(c(63.47,10.32),c(63.37,10.54),type=paste0(baseUrl,apiKey)),proj=CRS('+init=epsg:32632'))
I tried replacing satellite-streets-v9 with mapbox or simply deleting this directory, but it doesn't work. I don't know how to add my API key to the original command openmap(c(63.47,10.32),c(63.37,10.54),type='mapbox'). I couldn't find anything useful on mapbox's website, either.
I had to enter Mapbox Studio, create a default style (similar to the mapbox style I desired), to see on the "Layer overview" window that their default theme is called "Mapbox Streets v8". From there, I guessed that I should use
https://api.mapbox.com/styles/v1/mapbox/streets-v8/tiles/256/{z}/{x}/{y}
as my baseUrl. And it worked!

RStudio Viewer throws error

Issue
Some versions of RStudio throw an error in the Viewer pane of my javascript widget, and some don't.
Code
I've created a htmlwidget for my googleway package that plots a Google Map.
To reproduce this issue (if indeed it is an issue on your system) you can simply run this code
devtools::install_github("SymbolixAU/googleway")
library(googleway)
google_map(key = '') ## you don't need a key to see the error
But if you want to view a map, you'll need a Google Maps API key
Description
The issue I'm having is that on some versions of Rstudio the map shows in the Viewer pane, and in others it doesn't.
When I "inspect" the Viewer (right-click > inspect > console), I get the error
SyntaxError: Unexpected identifier 'i'. Expected either 'in' or 'of' in enumeration syntax.
Which links to a for loop inside the javascript (see screenshot and the source code)
This morning I upgraded Rstudio on the system that caused the error, but it's still giving the error.
The following two screenshots show two different Macs (both running OS Sierra) with Rstudio, with examples of
Rstudio v1.0.143 - not working
Rstudio v1.0.136 - working
Why does some versions of RStudio throw the error, and some don't?
#timelyportfolio's suggestion was instrumental (again!) in finding the solution.
I'm not convinced the issue was purely due to Rstudio, or there are other factors involved, especially as the widget works on an older version, but for now I'll leave this as the solution.
The let in the line
for (let i = 0; i < data.calls.length; i++) {
is not supported in all browsers, so changing it to var worked for that line (and all the lines that use a let).
I was also using this method for finding values in an array
data_.find(x => x.id === _id)
Which again is not supported in all browsers, so reverting to
function findById(source, id) {
for (var i = 0; i < source.length; i++) {
if (source[i].id === id) {
return source[i];
}
}
return;
}
seems to resolve that issue too.
et voila!

R radarchart rendering issues (no plot shown)

I would like to use to render a radarplot using the radarchart library in R. Everthing worked fine until I tried to change the colorscheme of the plot.
radarchart:::colourMatrix(diag(255, nrow=3))
After that, the radarchart is not plotted anymore.
What I did so far, was to remove (an re-install) radarchart and its dependencies htmltools and htmlwidgets.
=====
In Chrome the following errors are reported in the console:
Chart.min.js:12 Uncaught TypeError: Cannot convert undefined or null
to object
at Function.keys ()
at Object.o.each (Chart.min.js:12)
at Chart.min.js:14
at Object.o.each (Chart.min.js:12)
at a.determineDataLimits (Chart.min.js:14)
at a.update (Chart.min.js:13)
at Chart.min.js:12
at Object.o.each (Chart.min.js:12)
at Object.update (Chart.min.js:12)
at t.Controller.updateLayout (Chart.min.js:11) Chart.min.js:11 Uncaught TypeError: Cannot set property '_data' of undefined
at t.Controller.update (Chart.min.js:11)
at t.Controller.resize (Chart.min.js:11)
at Chart.min.js:11
at Chart.min.js:12
Before I removed both htmltools and htmlwidgets, there was another error, something like render.... not defined (but I don't remember precisely).

Resources