I have been trying to create an interactive map with sliders and drop down menu's for the NLD_muni dataset from the spData package. I am new to shiny, how can i change this code to make my interactive app show these variables in a more useful way.
At the moment. When selecting population and origin, it only reflects the origin when you click on various locations - and does not show any information about population.
library(spData)
data(NLD_muni)
pop_vars <- setdiff(names(NLD_muni), c("code", "name", "province", "geometry", "origin_native", "origin_west", "origin_non_west", "population", "pop_men", "pop_women"))
origin_vars <- setdiff(names(NLD_muni), c ("code", "name", "province", "geometry", "population", "pop_0_14", "pop_15_24", "pop_25_44", "pop_45_64", "pop_65plus", "pop_men", "pop_women"))
ui <- fluidPage(
tmapOutput("map"),
selectInput("pop", "Population", pop_vars),
selectInput("or", "Origin", origin_vars)
)
server <- function(input, output, session) {
output$map <- renderTmap({
tm_shape(NLD_muni) +
tm_polygons(world_vars[1])
})
output$map <- renderTmap({
tm_shape(NLD_muni) +
tm_polygons(origin_vars[1])
})
observe({
pop <- input$pop
tmapProxy("map", session, {
tm_shape(NLD_muni) +
tm_polygons(pop)
})
observe ({
or <- input$or
tmapProxy("map", session, {
tm_shape(NLD_muni) +
tm_polygons(or)
})
})
})
}
shinyApp(ui, server)