Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有tmap的交互式地图不会显示在Shiny app中,但会显示在Rstudio viewer中_R_Shiny_Leaflet_Maps_Tmap - Fatal编程技术网

带有tmap的交互式地图不会显示在Shiny app中,但会显示在Rstudio viewer中

带有tmap的交互式地图不会显示在Shiny app中,但会显示在Rstudio viewer中,r,shiny,leaflet,maps,tmap,R,Shiny,Leaflet,Maps,Tmap,我用tmap创建的交互式地图确实会显示在RStudio查看器中,但是,如果我尝试将其包含在我闪亮的应用程序中,它不会出现。我使用了tmap_传单函数、RenderLablet和传单输出。有人知道如何解决这个问题吗 下面是我在Shining应用程序中使用的示例代码: library(shiny) library(c(tmap,tmaptools,leaflet)) ui <- fluidPage( leafletOutput("test")) server

我用tmap创建的交互式地图确实会显示在RStudio查看器中,但是,如果我尝试将其包含在我闪亮的应用程序中,它不会出现。我使用了tmap_传单函数、RenderLablet和传单输出。有人知道如何解决这个问题吗

下面是我在Shining应用程序中使用的示例代码:

  library(shiny)
  library(c(tmap,tmaptools,leaflet))

  ui <- fluidPage(
        leafletOutput("test"))

  server <- function(input, output) {

     output$test <- renderLeaflet({

     # data is a shapefile with geometry properties and a mapping variable and facet variable. 

     tmap_mode("view")   
     map  <- tm_shape(data) +
             tm_polygons() +
             tm_facets(by = "facet_variable",nrow = 2, ncol = 2) +
             tm_shape(data) +
             tm_fill(col = "mapping_variable",
                     legend.show = T, 
                     colorNA = "grey",
                     palette = "Reds",n=9) +
             tm_shape(data) +
             tm_borders("white",alpha=.8, lwd=1.5) +
             tm_layout(outer.margins = 0) +
             tm_view(view.legend.position = c("left","bottom"))
     tmap_leaflet(map,mode="view",show=T)
     })
    }

  shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(c(tmap、tmaptools、传单))

ui通过一些虚拟数据,我可以看到地图

我不确定您是否可以这样加载包:
library(c(tmap、tmaptools、传单))
它给了我这个错误:

库(c(tmap、tmaptools、传单)中出错:'package'muss 哈本林奇1号酒店

我不认为有一个参数叫做
view.legend.position
。尝试使用
图例。仅定位

我认为问题来自
方面。(下面的示例不使用它们)

库(闪亮)
图书馆(tmap)
图书馆(tmaptools)
图书馆(单张)
图书馆(sp)
Sr1=多边形(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
Sr2=多边形(cbind(c(5,4,2,5),c(2,3,2,2)))
Sr3=多边形(cbind(c(4,4,5,10,4),c(5,3,2,5,5)))
Sr4=多边形(cbind(c(5,6,6,5,5),c(4,4,3,3,4)),孔=真)
Srs1=多边形(列表(Sr1),“s1”)
Srs2=多边形(列表(Sr2),“s2”)
Srs3=多边形(列表(Sr3、Sr4),“s3/4”)
SpP=空间多边形(列表(Srs1、Srs2、Srs3),1:3)

grd您可以使用tmap函数与以下代码一起绘制分面贴图。 生成的地图如下所示:

库(tidyverse)
图书馆(tmap)
图书馆(tmaptools)
图书馆(rgdal)
图书馆(dplyr)
图书馆(单张)
#加载形状并选择荷兰四大城市

你能提供一些数据吗?非常感谢你的回复!如果没有面,它也可以很好地处理原始数据:)。仍然想知道为什么在刻面上是不可能的?至于图书馆,那是一个打字错误。我确实在我的文件中分别加载了它们。请注意,view.legend.position最近已替换了tm_view函数()中的legend.position。正确,我仍在使用tmap 1.11。我不知道它将如何在地图上放置不同的面。你知道在tmap上使用刻面的例子吗?
library(shiny)
library(tmap)
library(tmaptools)
library(leaflet)
library(sp)

Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))
Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5)))
Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE)

Srs1 = Polygons(list(Sr1), "s1")
Srs2 = Polygons(list(Sr2), "s2")
Srs3 = Polygons(list(Sr3, Sr4), "s3/4")
SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3)

grd <- GridTopology(c(1,1), c(1,1), c(10,10))
polys <- as(grd, "SpatialPolygons")
centroids <- coordinates(polys)
x <- centroids[,1]
y <- centroids[,2]
z <- 1.4 + 0.1*x + 0.2*y + 0.002*x*x
ex_1.7 <- SpatialPolygonsDataFrame(polys,
                                   data=data.frame(x=x, y=y, z=z, row.names=row.names(polys)))
ex_1.7$face <- c(rep(1, 50), rep(2,50))


ui <- fluidPage(
  leafletOutput("test"))

server <- function(input, output) {

  output$test <- renderLeaflet({

    # data is a shapefile with geometry properties and a mapping variable and facet variable. 

    # tmap_mode("view")   
    map  <- tm_shape(ex_1.7) +
      tm_polygons() +
      # tm_facets(by = "facet_variable",nrow = 2, ncol = 2) +
      # tm_facets(by = "face", nrow = 2, ncol = 2) +
      tm_shape(ex_1.7) +
      # tm_fill(col = "mapping_variable",
      tm_fill(col = "y",
              legend.show = T,
              colorNA = "grey",
              palette = "Reds",n=9) +
      tm_shape(ex_1.7) +
      tm_borders("white",alpha=.8, lwd=1.5) +
      tm_layout(outer.margins = 0) +
      tm_view(legend.position = c("left","bottom"))


    tmap_leaflet(map)
  })
}

shinyApp(ui = ui, server = server)
library(tidyverse)
library(tmap)
library(tmaptools)
library(rgdal)
library(dplyr)
library(leaflet)

# Loading shape and select four largest cities in the Netherlands
country  <- read_shape("/local_directory/wijk_2017.shp")

# Cleaning and preparing data
cities   <- country %>% 
            filter(GM_CODE %in% c("GM0363","GM0599","GM0518","GM0344"),
                  !WK_CODE %in% c("WK036399","WK059999","WK051899","WK034499"))
cities   <- cities %>%
            mutate(WK_NAAM = as.character(WK_NAAM),
                 OPP_TOT = as.numeric(as.character(OPP_TOT)),
                 OPP_TOT = cut(OPP_TOT,breaks = c(-Inf,seq(500,2000,by=500),Inf)))

# Plotting facetted tmap of four largest cities in the Netherlands.
tmap_mode("view")
tm_shape(cities) +
  tm_polygons() +
  tm_facets(by = "GM_NAAM",
            nrow = 2, ncol = 2) +
  tm_shape(cities) +
  tm_fill(col = "OPP_TOT",
          legend.show = T, 
          colorNA = "grey",
          title = "Total area per neighbourhood",
          textNA = "No data",
          palette = "Greens",n=5,
          id = "WK_NAAM") +
  tm_shape(cities) +
  tm_borders("white",alpha=.8, lwd=1.5) +
  tm_layout(outer.margins = 0) +
  tm_view(view.legend.position = c("left","bottom"))