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
Leaflet map not rendering in RStudio Viewer #192
Comments
Have you tried zooming, sometimes I find that the tiles are all grey at first and with a zoom they show up. Not ideal, but a workaround. |
The same issue here! |
Same issue |
When teaching a recent workshop on this I found that users with older versions of RStudio were the ones having trouble. A version that works for me is 0.99.489. Also, this is not a solution but a workaround, you can use |
Additional info on this behavior is observed on Windows (Win 7), but I don't see this behavior on MacOS 10.X++ (Yosemite). Map Tiles appear fine on MacOS. |
Same issue here. I was viewing maps just fine in RStudio viewer and now it saves a html map. In addition that html map did not render layers that were working when it was showing up in RStudio ("error is map$x: $ operator is invalid for atomic vectors"). I think it might have something to do with using geoJSON. After I played around with geoJSON formats and now have gone back to spatialXXdataframes this issue popped up. Any solutions? .....30 seconds later..... Well all I had to do was ask to figure out my own problem. I had loaded the leafletR package to convert spatialXXdataframes to geoJSONs (which didnt really work) which appeared to mask the normal leaflet() command. I tried re running all my code without leafletR loaded and my map came up in RStudio like it was doing. |
The same issue here on Windows 7. I have no problem with plotting a few states at tract level, but RStudio stops work if I render all states at once. No problem with my Mac. |
@Huade Could you provide a reproducible sample code ? Also details of R and RStudio versions please. |
@bhaskar-vk Of course!
library(haven)
library(dplyr)
library(leaflet)
library(rgdal)
library(tigris)
# Read school district finance data
# https://nces.ed.gov/ccd/f33agency.asp
# https://nces.ed.gov/ccd/data/zip/sdf13_1a.sas7bdat.zip
options(stringsAsFactors = F)
ccd_raw <- read_sas("./data/sdf13_1a.sas7bdat")
ccd <- ccd_raw %>%
mutate(property_tax = ifelse(T06>=0, T06, NA),
total_local_revenue = ifelse(TLOCREV >= 0, TLOCREV, NA),
pct_property_tax = 100*property_tax / total_local_revenue) %>%
select(LEAID, pct_property_tax) %>%
filter(!is.na(pct_property_tax))
# Read School District Geographic Relationship Files
# https://nces.ed.gov/programs/edge/geographicRelationshipFiles.aspx
# https://nces.ed.gov/programs/edge/data/GRF15.zip
lea_geo_link <- read_sas("./data/grf15_lea_tract.sas7bdat") %>%
select(LEAID, GEOID = STCOTRACT)
# Read School District Boundaries
# https://nces.ed.gov/programs/edge/geographicDistrictBoundary.aspx
# https://nces.ed.gov/programs/edge/data/SCHOOLDISTRICT_SY1314_TL15.zip
school_dist_boundary <- readOGR("./shp/schooldistrict_sy1314_tl15.shp",
layer = "schooldistrict_sy1314_tl15", verbose = FALSE)
pct_property_tax_merged_full <- geo_join(school_dist_boundary, ccd, "GEOID", "LEAID")
pct_property_tax_merged <- pct_property_tax_merged_full[pct_property_tax_merged_full$STATEFP %in% unique(pct_property_tax_merged_full$STATEFP)[50],]
popup <- paste0("LEAID: ", pct_property_tax_merged$LEAID, "<br>",
pct_property_tax_merged$NAME, "<br>",
"Percent of Property Tax as Local Revenue: ", round(pct_property_tax_merged$pct_property_tax,2), "%")
pal <- colorNumeric(
palette = "YlGnBu",
domain = pct_property_tax_merged$pct_property_tax
)
map1<- leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = pct_property_tax_merged,
fillColor = ~pal(pct_property_tax),
color = "#b2aeae",
fillOpacity = 0.7,
weight = 1,
smoothFactor = 0.2,
popup = popup) %>%
addLegend(pal = pal,
values = pct_property_tax_merged$pct_property_tax,
position = "bottomright",
title = "Percent of Property Tax as Local Revenue",
labFormat = labelFormat(suffix = "%"))
map1 |
Thanks @Huade I'll need the data files as well to try and reproduce it here. |
I have updated my code and included download addresses, @bhaskarvk . You may want to try visit the webpage (and accept their terms) if the direct download does not work well. Thanks for reproducing! |
+1 thanks I'll take a look at this sometime this week. |
any update on possible remedial steps for this issue? I get the same behaviour using RStudio 0.99.903 on Windows 10 whereby the map itself doesn't render; rather I only see the grey background. |
+1 with this issue! |
@robsalasco @Huade @gfcronin Are you guys by any chance behind a web proxy ? |
I know you didn't direct the comment at me, but yes, I am. |
Yes; Windows 7 is my office computer. Actually, the issue still persists if I run Rstudio on EC2 on this Windows 7 computer. |
@bhaskarvk Any news on this? I have the same issue and yes, I am behind a web proxy. |
@jcheng5 wasn't this fixed in one of the recent RStudio versions ? |
@bhaskarvk @jcheng5 . Would be great if one of the recent RStudio versions solved the problem. We're currently using a slightly older version (0.99.879), which should be updated shortly. |
FWIW I am not officially involved with RStudio so I can't comment in any official capacity, but I seem to remember this issue being fixed from some discussion I had seen. |
Is there a way around this bug? Demonstrable both on the R command line and in Rstudio (nightly build, linux 64 ubuntu1.1.75) [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: other attached packages: loaded via a namespace (and not attached): |
Here is actual addtile function, when you generate html file from htmlwidget, it create path as file://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png function (map, urlTemplate = "//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
attribution = NULL, layerId = NULL, group = NULL, options = tileOptions())
{
options$attribution = attribution
if (missing(urlTemplate) && is.null(options$attribution))
options$attribution = paste("© <a href=\"http://openstreetmap.org\">OpenStreetMap</a>",
"contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>")
invokeMethod(map, getMapData(map), "addTiles", urlTemplate,
layerId, group, options)
} FInally I solved simillar issue by changing function parameter as : addTiles = function (map, urlTemplate = "**http:**//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
attribution = NULL, layerId = NULL, group = NULL, options = tileOptions())
{
options$attribution = attribution
if (missing(urlTemplate) && is.null(options$attribution))
options$attribution = paste("© <a href="http://openstreetmap.org\">OpenStreetMap",
"contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA")
invokeMethod(map, getMapData(map), "addTiles", urlTemplate,
layerId, group, options)
} |
kgavhane702 thanks for the tip!! Absolutely works when setting http path in addTiles function |
@kgavhane702 @ferjmele That bug has been fixed in the GitHub version of leaflet, though not re-released to CRAN yet. Though the fix by @kgavhane702 works well and should continue to work. |
ok!! Thanks! |
@ferjmele welcome. |
Hi - I'm still experiencing this issue even so I use the leaflet package version of github and the lastest release of RStudio (Version 1.0.136). Here is the code I'm testing: m <- leaflet() %>% m # Print the map` The code is running without error nor messages. It generates a map in the Rstudio viewer with a grey background and a marker but no tiles in the background. When I try to view the map in a browser (IE or Chrome), it succesfully shows the expected results. Here are my session info: locale: attached base packages: other attached packages: loaded via a namespace (and not attached): We also tested with no success:
Thx for your help |
@Mamasquee Do you get the same results with a 1.1 build of RStudio (https://dailies.rstudio.com)? |
thanks @jcheng5 |
@Mamasquee It's a different bug then. See this one: #240 |
Thanks @kgavhane702 |
1 similar comment
Thanks @kgavhane702 |
Thanks @kgavhane702. Great tip. I was getting a grey screen with no tiles in my browser with leaflet on my Mac but when I added "http" to the urlTemplate in addTiles, everything works. library (leaflet) |
Welcome |
@kgavhane702 I used your code but it still didn't work. The image I got is like this |
Hey @eddiecylin leaflet community has solved similar issue on GitHub. download GitHub version of leaflet, and you will definitely overcome with this error. |
if (!require('devtools')) install.packages('devtools') |
Hi @kgavhane702, I tried but I am sorry that it still didn't work out. I even switched another computer and installed RStudio and used |
@eddiecylin What operating system, and version of RStudio? And are you on a corporate network (especially one with some kind of proxy setup)? |
@jcheng5 @kgavhane702 thanks for your help. I think I figured out why. I made a mistake by putting longitude and latitude parameters in the wrong order. So my map of Manhattan always showed up next to Brazil and had to zoom in all the way to show. I made a correction and set the |
1. map background not printing. see rstudio/leaflet#192 for fix--adding url to addTiles() 2. fixed function for downloading all metadata
Great..! |
For me (Ubuntu 18.04) works in browser but not in RStudio
|
Locking conversation as it is old. Please install a daily build of RStudio (v1.2) if you are experiencing https issues when loading map tiles with leaflet. If this is not related to loading https on windows and linux, please file a new issue. |
When I run the very simple example shown on the R Leaflet tutorial, I just get a grey screen with the zoom buttons. Here is the code I'm running:
I read through the closed issues and found one similar to my issue here: #112 However, updating
htmlwidgets
, which I assume is the only library I'd need to worry about, didn't work. When I click "View in new window", the map displays fine. In addition, if Ihtmlwidgets::saveWidget(map, file="map.html")
, the file saves fine and can be opened with my web browsers. I'm not sure why it won't display in the RStudio Viewer though. Any suggestions would be greatly appreciated.The text was updated successfully, but these errors were encountered: