Здравствуйте, после нескольких попыток я достиг этого решения:
библиотека (блестящая) библиотека (листовка) библиотека (leaflet.extras)
load ("./ Datos.Rdata")
ui <- fluidPage (titlePanel ("Santia go de Compostela"), </p>
mainPanel(
selectInput("option", "Option:",
choices= c("Población Total","Población Masculina","Población Femenina","Población < 16 años")),
leafletOutput("map")
))
server <- функция (вход, выход) {</p>
colorpal <- reactive({
if(input$option == "Población Total") {
colorBin("Blues",dat1$`Población Total`,bins = 5)
} else if (input$option == "Población Masculina"){
colorBin("Reds",dat1$`Población Masculina`,bins = 5)
} else if (input$option == "Población Femenina"){
colorBin("Oranges",dat1$`Población Femenina`,bins = 5)
} else
colorBin("Greens",dat1$`Población < 16 años`,bins = 5)
})
ventana <- reactive({
if(input$option == "Población Total") {
paste0("<b>", "Población Total: ", "</b>", as.character(dat1$`Población Total`))
} else if (input$option == "Población Masculina"){
paste0("<b>", "Población Masculina: ", "</b>", as.character(dat1$`Población Masculina`))
} else if (input$option == "Población Femenina"){
paste0("<b>", "Población Femenina: ", "</b>", as.character(dat1$`Población Femenina`))
} else
paste0("<b>", "Población < 16 años: ", "</b>", as.character(dat1$`Población < 16 años`))
})
output$map <- renderLeaflet({
leaflet() %>% setView(-8.53, 42.90, zoom = 10)%>%
addBootstrapDependency() %>%
# Base groups
addProviderTiles(providers$CartoDB.DarkMatter , group = "CartoDB.DarkMatter") %>%
addProviderTiles(providers$Esri.WorldImagery , group = "Esri.WorldImagery") %>%
addMiniMap(
tiles = providers$Esri.WorldImagery,
toggleDisplay = TRUE)
})
observe({
pal <- colorpal()
popup1 <-ventana()
proxy <- leafletProxy("map", data = dat1)
proxy %>% clearShapes() %>%clearControls()
if (input$option == "Población Total") {
proxy %>% addPolygons(color = "#444444" ,
weight = 1,
smoothFactor = 0.5,
opacity = 1.0,
fillOpacity = 0.5,
popup = popup1 ,
fillColor = ~pal(dat1[[input$option]]))%>%
addLegend(position = "topright", pal = pal, values = dat1[[input$option]] ,
title = ~paste(input$option)) }
else if (input$option == "Población Masculina") {
proxy %>% addPolygons(color = "#444444" ,
weight = 1,
smoothFactor = 0.5,
opacity = 1.0,
fillOpacity = 0.5,
popup = popup1 ,
fillColor = ~pal(dat1[[input$option]]))%>%
addLegend(position = "topright", pal = pal , values = dat1[[input$option]] ,
title = ~paste(input$option)) }
else if (input$option == "Población Femenina") {
proxy %>% addPolygons(color = "#444444" ,
weight = 1,
smoothFactor = 0.5,
opacity = 1.0,
fillOpacity = 0.5,
popup = popup1 ,
fillColor = ~pal(dat1[[input$option]]))%>%
addLegend(position = "topright", pal = pal , values = dat1[[input$option]] ,
title = ~paste(input$option)) }
else
proxy %>% addPolygons(color = "#444444" ,
weight = 1,
smoothFactor = 0.5,
opacity = 1.0,
fillOpacity = 0.5,
popup = popup1 ,
fillColor = ~pal(dat1[[input$option]]))%>%
addLegend(position = "topright", pal = pal , values = dat1[[input$option]] ,
title = ~paste(input$option))
})
}
блестящее приложение (пользовательский интерфейс = сервер, сервер = сервер)