I have the dataframe below for which I want to create a choropleth map. I downloaded the germany shapefile from here and now Im trying to display it via shiny app using tmap interactive version. Is this possible? Any other interactive solutions via shiny?
library(tidyverse)
library(sf)
library(shiny)
library(ggplot2)
library(tmap)
region<-c("09366",
"94130",
"02627",
"95336",
"08525",
"92637",
"95138",
"74177",
"08606",
"94152" )
value<-c( 39.5,
519.,
5.67,
5.10,
5.08,
1165,
342,
775,
3532,
61.1 )
df<-data.frame(region,value)
ui <- fluidPage(
plotOutput("map")
)
server <- function(input, output) {
germany_sf <- sf::st_read(dsn = "plz-gebiete.shp") %>%
left_join(df, by = c("plz" = "region"))
output$map<-renderPlot({
tmap_mode("view")
tm_shape(shp = germany_sf) +
tm_polygons(col = "value", border.alpha = 0)
})
}
shinyApp(ui, server)
Use tmapOutput
and renderTmap
instead of plotOutput
and renderPlot
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.