Description Usage Arguments Value Author(s) Examples
View source: R/polygonChooser.R
Provides a dropdown list of polygons available for mapping, sorted alphabetically.
1 2 3 4 5 | polygonChooserUI(id)
polygonChooser(input, output, session, rctPolygonList,
selectedPoly = NULL, uploadOpts = list(auth = NULL, path = NULL, user
= NULL), studyArea = NULL)
|
id |
An id string that corresponds with the id used to call the module's UI function. |
input |
shiny server input object |
output |
shiny server output object |
session |
shiny server session object |
rctPolygonList |
A reactive nested list with the following structure: # TODO: fill this in |
selectedPoly |
The name of the polygon to select by default. |
uploadOpts |
A list of options for use with file uploads:
|
studyArea |
A |
A reactive list with elements polygons
(a list of polygons) and
selected
(the name of the selected polygon).
Alex Chubaty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ## Not run:
if require(SpaDES.tools) {
library(leaflet)
library(magrittr)
library(shiny)
library(sp)
shinyApp(
ui = fluidPage(
htmlOutput("infobox"),
leafletOutput("map"),
polygonChooserUI("polyPicker")
),
server = function(input, output, session) {
dummyPoly <- function() {
randomPolygon(matrix(c(-120, 60), ncol = 2), 100)
}
dummyPoly1 <- dummyPoly()
dummyPoly2 <- dummyPoly()
dummyPoly3 <- dummyPoly()
dummyPoly4 <- dummyPoly()
tmpf <- tempfile(fileext = ".shp")
raster::shapefile(dummyPoly4, filename = tmpf)
polygonList <- reactive(list(
caribou = dummyPoly1,
ecozones = dummyPoly2,
fmu = dummyPoly3
))
out <- callModule(polygonChooser, "polyPicker", polygonList, "ecozones",
uploadOpts = list(
auth = TRUE,
path = dirname(tmpf),
user = "username"
))
updatedPolygonList <- reactive(out()$polygons)
chosenPolyName <- reactive(out()$selected)
chosenPoly <- reactive(updatedPolygonList()[[chosenPolyName()]])
output$infobox <- renderUI({
fluidRow(
h4("Currently viewing the ", chosenPolyName(), " polygon.")
)
})
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addPolygons(data = spTransform(chosenPoly(), CRSobj = proj4stringLFLT))
})
}
)
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.