Tmap Facets didn't work 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 seems didn't work (my code have no error but the maps didn't show up) in R shiny. When I run the regular R code of facets maps, it works fine.

Here is my code:

library(shiny)    # for shiny apps
library(leaflet)  # renderLeaflet function
library(tmap)
library(readr)
library(sf)
library(dplyr)
# data import and processing
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)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.