【发布时间】:2019-01-07 15:50:29
【问题描述】:
我使用 tmap 创建的交互式地图确实显示在 RStudio 查看器中,但是,如果我尝试将它包含在我的 Shiny 应用程序中,它不会出现。我使用了 tmap_leaflet 函数、renderLeaflet 和 LeafletOutput。有谁知道如何解决这个问题?
下面是我在 Shiny 应用程序中使用的示例代码:
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)
【问题讨论】:
-
你能包含一些数据吗?