Created
August 27, 2020 18:35
-
-
Save z3tt/18e32d34bd82bb0e4f5ad2547a3e1795 to your computer and use it in GitHub Desktop.
tmap in shiny
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(tmap) | |
data(World) | |
world_vars <- setdiff(names(World), c("iso_a3", "name", "sovereignt", "geometry")) | |
ui <- fluidPage( | |
tmapOutput("map"), | |
selectInput("var", "Variable", world_vars) | |
) | |
server <- function(input, output, session) { | |
output$map <- renderTmap({ | |
tm_shape(World) + | |
tm_polygons(world_vars[1], zindex = 401) | |
}) | |
observe({ | |
var <- input$var | |
tmapProxy("map", session, { | |
tm_remove_layer(401) + | |
tm_shape(World) + | |
tm_polygons(var, zindex = 401) | |
}) | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment