Haihong Huang
Haihong Huang

Reputation: 11

tmap facets didn't show up in R shiny

I am trying to use tmap facets to create a side-by-side synchrounous choropleth map (refer to https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html#facets) but the facet function didn't work in R shiny (my code have no error but the maps didn't show up). However, when I run the regular R code of facets maps, it works fine. Anyone can help me?

Here is my code:

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)

Upvotes: 1

Views: 186

Answers (1)

Meo
Meo

Reputation: 160

I run into the same problem. It doesn't seem like the error was fixed yet.

Upvotes: 0

Related Questions