2

Background

I'm no familiar with Javascript language, then I have tried the package leaflet.minicart using R inside the Jupyter notebook.

Writting the example code as follows:

library(leaflet)

m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
m  # Print the map

However, the output cell can not be well represented. Maybe the figure below is not very clear, the output map is fixed to a narrow strip.

enter image description here

Meanwhile, I opened the saved html file (uploaded here) in browser, the background map was not able to be shown.

enter image description here

MLavoie
  • 9,671
  • 41
  • 36
  • 56
Han Zhengzu
  • 3,694
  • 7
  • 44
  • 94
  • Did you find a solution for this? The proposed one is based on RStudio but not Jupyter. I am having the same issue than you (using your code example) – GCGM Mar 05 '20 at 11:38

2 Answers2

0

I cannot reproduce your first problem, the map displays fine in my RStudio Viewer. For the grey html background it was answered here:

[https://gis.stackexchange.com/questions/187926/leaflet-output-is-grey][1]

use:

library(leaflet);library(htmlwidgets)

m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")%>% addProviderTiles(providers$OpenStreetMap) 
saveWidget(m, file="m.html")
Antonios
  • 1,919
  • 1
  • 11
  • 18
  • I think the question is about the problem in visualization in Jupyter not in RStudio. Getting the same problem myself. The map can be seen but the output cell in Jupyter is very narrow – GCGM Mar 05 '20 at 11:37
0

Source: https://www.r-bloggers.com/2018/04/r-htmlwidgets-in-jupyter-notebooks/

library(leaflet)
library(htmlwidgets)
library(IRdisplay)
m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")

saveWidget(m, 'demo.html', selfcontained = TRUE)
display_html('<iframe src="demo.html"></iframe>')

enter image description here

Ferroao
  • 3,042
  • 28
  • 53