R小册子RStudio查看器空白(灰色)地图[Windows 7] [英] R leaflet RStudio Viewer blank (grey) map [Windows 7]

查看:490
本文介绍了R小册子RStudio查看器空白(灰色)地图[Windows 7]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在RStudio中使用传单在查看器中生成空白地图。
只能看到标记。
在控制台中不能看到警告或错误信息。
当我使用闪亮的时候,它在RStudio查看器中是一样的,但是通过在闪亮的服务器上侦听,可以在FireFox浏览器中看到地图。

  devtools :: install_github(rstudio / leaflet); library(leaflet)
m< - leaflet()%>%
addTiles()%>%#Add default OpenStreetMap地图瓷砖
addMarkers(lng = 174.768,lat = -36.852,
popup =R的出生地)
m#打印地图

sessionInfo()

R版本3.2.0(2015-04-16)
平台:i386-w64-mingw32 / i386(32位)
运行于:Windows 7(build 7601) Service Pack 1

locale:
[1] LC_COLLATE = German_Germany.1252 LC_CTYPE = German_Germany.1252 LC_MONETARY = German_Germany.1252
[4] LC_NUMERIC = C LC_TIME = German_Germany.1252

附加基础包:
[1]统计图形grDevices utils数据集方法基础

其他附加软件包:
[1] geosphere_1.3-13 maps_2.3-9 WDI_2.4 RJSONIO_1.3-0 rgdal_1.0-4 sp_1.1-1
[7] leaflet_1.0.0 shiny_0.12.0 dplyr_0.4.1 readxl_0.1.0 memoise_0.2.1

加载通过命名空间(并未附加):
[1] digest_0.6.8 htmltools_0.2.6 R6_2.0.1 curl_0.9 assertthat_0.1 grid_3.2.0
[7] bitops_1.0-6 stringr_1.0.0 devtools_1。 8.0 httr_0.6.1 httpuv_1.3.2 git2r_0.10.1
[13] rversions_1.0.1 lattice_0.20-31 mime_0.3 DBI_0.3.1 xml2_0.1.1 rstudioapi_0.3.1
[19] jsonlite_0.9.16 stringi_0.4 -1 magrittr_1.5 RCurl_1.95-4.6 yaml_2.1.13 tools_3.2.0
[25] parallel_3.2.0 htmlwidgets_0.5 xtable_1.7-4 lazyeval_0.1.10 Rcpp_0.11.6


闪亮代码:

  
library(leaflet)

r_colors< - rgb(t(col2rgb(colors())/ 255))
names(r_colors)< - colors()

ui< - fluidPage(leafle tOutput(mymap),
p(),
actionButton(recalc,New points))

服务器< - function(input,output,session) {
points< - eventReactive(input $ recalc,{
cbind(rnorm(40)* 2 + 13,rnorm(40)+48)
},ignoreNULL = FALSE)

output $ mymap< - renderLeaflet({
leaflet()%>%
addProviderTiles(Stamen.TonerLite,
options = providerTileOptions(noWrap = TRUE) )%>%
addMarkers(data = points())
})
}

shinyApp(ui,server)

聆听http://127.0.0.1:5916


解决方案

在你的第一个例子(非Shiny)中尝试的一件事是使用 addProviderTiles 来代替 addTiles

  m<  -  leaflet()%>%
addProviderTiles(providers $ OpenStreetMap)%>%
addMarkers(lng = 174.768,lat = -36.852,
popup =R的出生地)
m#打印地图

同样的 addProviderTiles 替换也可以解决RStudio查看器中的问题,或者您可以考虑启动Shiny direct to如此处所述的Firefox,作为解决方法。

Using leaflet within RStudio produces blank maps in the viewer. Only the markers can be seen. No warning or error message can be seen in the console. When I use shiny it's the same in the RStudio viewer but map can be seen in the FireFox browser by listening on the shiny server.

devtools::install_github("rstudio/leaflet");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

sessionInfo()

R version 3.2.0 (2015-04-16)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] geosphere_1.3-13 maps_2.3-9       WDI_2.4          RJSONIO_1.3-0    rgdal_1.0-4      sp_1.1-1        
 [7] leaflet_1.0.0    shiny_0.12.0     dplyr_0.4.1      readxl_0.1.0     memoise_0.2.1   

loaded via a namespace (and not attached):
 [1] digest_0.6.8     htmltools_0.2.6  R6_2.0.1         curl_0.9         assertthat_0.1   grid_3.2.0      
 [7] bitops_1.0-6     stringr_1.0.0    devtools_1.8.0   httr_0.6.1       httpuv_1.3.2     git2r_0.10.1    
[13] rversions_1.0.1  lattice_0.20-31  mime_0.3         DBI_0.3.1        xml2_0.1.1       rstudioapi_0.3.1
[19] jsonlite_0.9.16  stringi_0.4-1    magrittr_1.5     RCurl_1.95-4.6   yaml_2.1.13      tools_3.2.0     
[25] parallel_3.2.0   htmlwidgets_0.5  xtable_1.7-4     lazyeval_0.1.10  Rcpp_0.11.6     

Shiny code:

library(shiny)
library(leaflet)

r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()

ui <- fluidPage(leafletOutput("mymap"),
                p(),
                actionButton("recalc", "New points"))

server <- function(input, output, session) {
  points <- eventReactive(input$recalc, {
    cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
  }, ignoreNULL = FALSE)

  output$mymap <- renderLeaflet({
    leaflet() %>%
      addProviderTiles("Stamen.TonerLite",
                       options = providerTileOptions(noWrap = TRUE)) %>%
      addMarkers(data = points())
  })
}

shinyApp(ui, server)

Listening on http://127.0.0.1:5916

解决方案

One thing to try in your first example (non-Shiny) is using addProviderTiles in place of addTiles.

m <- leaflet() %>%
  addProviderTiles(providers$OpenStreetMap) %>%  
  addMarkers(lng = 174.768, lat = -36.852,
         popup = "The birthplace of R")
m  # Print the map

The same addProviderTiles substitution may fix the issue within the RStudio viewer as well, or you could consider launching Shiny direct to Firefox as described here, as a work around.

这篇关于R小册子RStudio查看器空白(灰色)地图[Windows 7]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆