tmap构面未出现在R Shiny中

时间:2019-02-12 01:04:14

标签: r shiny tmap

我正在尝试使用tmap构面来创建并排同步的Choropleth贴图(请参阅https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html#facets),但是facet函数在R Shiny中不起作用(我的代码没有错误,但是贴图没有出现)。但是,当我运行构面贴图的常规R代码时,效果很好。有人可以帮助我吗?

这是我的代码:

library(shiny)    # for shiny apps
library(leaflet)  # renderLeaflet function
#library(spData)   # loads the world dataset 
library(tmap)
library(readr)
library(sf)
library(dplyr)
library(mapview) # for interactive maps
#tmap_mode("view")
CANCER_raw <- st_read("F:/appR-upload/cancer_sample_data.csv")
SD_SRA_raw <- st_read("F:/appR-upload/polygon/polygon.shp")

cancer_data <- data.frame(
      SRAID = CANCER_raw$GeoID,   
      SRA_Name = CANCER_raw$Geography, 
      Condition = CANCER_raw$CONDITION,
      Outcome = CANCER_raw$OUTCOME,
      Year = CANCER_raw$Year,
      Total = CANCER_raw$Total,
      TotalRate = CANCER_raw$TotalRate,
      AARate = CANCER_raw$AARate
    )

sd_sra <- data.frame(
      SRAID = SD_SRA_raw$SRA, 
      SRA_Name = SD_SRA_raw$SRA_Name,
      geometry = SD_SRA_raw$geometry
    )

sd_sra_cancer <- st_as_sf(left_join(sd_sra, cancer_data, by = 'SRAID'))


ui <- fluidPage(
  leafletOutput(outputId = "map")
)

server <- function(input, output, session) {

    output$map <- renderLeaflet(
      {
        tmap_mode("view")
        tm <- tm_shape(sd_sra_cancer) +
          tm_polygons(c("Total", "TotalRate")) +
          tm_facets(sync = TRUE, ncol = 2)

        tmap_leaflet(tm)
      }
    )}

shinyApp(ui, server)

0 个答案:

没有答案