I have a shiny application where I have a leaflet-map and checkboxes.
What I want to do is the following.
I want to render a shapefile when a checkbox is checked and remove it when the checkbox gets unchecked.
ui.R
library(shiny)
library(leaflet)
# Define UI for application that draws a histogram
shinyUI(
fluidPage(
leafletOutput("mymap"),
checkboxInput(inputId = "direction",
label = strong("Traffic Directions"),
value = FALSE),
checkboxInput(inputId = "madrid",
label = strong("Madrid Outlines"),
value = FALSE)
)
)
server.R
library(shiny)
library(rgdal)
shinyServer(function(input, output, session) {
##SHAPEFILES
madridShape <- readOGR("./madridshapefile/", "Distritos")
directions <- readOGR("./directions/", "directions")
output$mymap <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron,
options = providerTileOptions(noWrap = )
) %>%
setView(lng = -3.8196207,
lat = 40.4678698,
zoom = 10)
})
})
What do I have to do in order to achieve my goal?
I tried something like this for when the checkbox gets checked :
if (input$direction == true){
output$mymap <- addPolygons(data=madridShape,weight=1,col = 'black') %>%
}
I seem to miss something though because it's not working.
Aucun commentaire:
Enregistrer un commentaire