将 shiny 与 tmap 相结合以显示交互式地图

Combine shiny with tmap to display interactive map

我有下面的数据框,我想为其创建等值线图。我从 here 下载了德国 shapefile,现在我正在尝试使用 tmap 交互式版本通过闪亮的应用程序显示它。这可能吗?通过闪亮的任何其他交互式解决方案?

library(tidyverse)
library(sf)
library(shiny)
library(ggplot2)
library(tmap)

region<-c("09366", 
          "94130", 
          "02627", 
          "95336", 
          "08525", 
          "92637", 
          "95138", 
          "74177", 
          "08606", 
          "94152" )


value<-c( 39.5, 
          519.,  
          5.67,
          5.10,
          5.08,
          1165,  
          342,  
          775,  
          3532,  
          61.1 )

df<-data.frame(region,value)

ui <- fluidPage(
  plotOutput("map")
)

server <- function(input, output) {
  germany_sf <- sf::st_read(dsn = "plz-gebiete.shp") %>% 
    left_join(df, by = c("plz" = "region"))
output$map<-renderPlot({
  tmap_mode("view")
  
  tm_shape(shp = germany_sf) + 
    tm_polygons(col = "value", border.alpha = 0)
})  
  
  
}

shinyApp(ui, server)

使用 tmapOutputrenderTmap 代替 plotOutputrenderPlot