polygonChooser: Shiny module for selecting a polygon to display an a map

Description Usage Arguments Value Author(s) Examples

View source: R/polygonChooser.R

Description

Provides a dropdown list of polygons available for mapping, sorted alphabetically.

Usage

1
2
3
4
5
polygonChooserUI(id)

polygonChooser(input, output, session, rctPolygonList,
  selectedPoly = NULL, uploadOpts = list(auth = NULL, path = NULL, user
  = NULL), studyArea = NULL)

Arguments

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: auth logical indicating whether user is authorized to upload; path a directory path to use for file uploads; user the current username (used for creating user-specific paths); The default for all options is NULL, which means do not use.

studyArea

A Spatial object used as a template for post-processing the uploaded polygon, which is cropped, reprojected, etc. to match studyArea. See postProcess.

Value

A reactive list with elements polygons (a list of polygons) and selected (the name of the selected polygon).

Author(s)

Alex Chubaty

Examples

 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)

PredictiveEcology/SpaDES.shiny documentation built on Nov. 11, 2019, 7:12 p.m.