The interactive map I created with tmap does show up in the RStudio Viewer, however, if I try to include it in my Shiny application it does not appear. I've used the tmap_leaflet function, renderLeaflet and leafletOutput. Does anyone know how to solve this?
Below is an example code of what I used in my Shiny application:
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)