-
Notifications
You must be signed in to change notification settings - Fork 33
/
shiny_modules.R
74 lines (64 loc) · 1.63 KB
/
shiny_modules.R
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
\dontrun{
library(mapedit)
library(mapview)
library(shiny)
# select as a module
m = leaflet(breweries91) %>%
addCircleMarkers(weight = 1, layerId = 1:nrow(breweries91))
ui <- tagList(
selectModUI("test-mod"),
DT::dataTableOutput("selected")
)
server <- function(input, output, session) {
selections <- callModule(selectMod, "test-mod", m)
output$selected <- DT::renderDataTable({DT::datatable(selections())})
observe({str(selections())})
}
shinyApp(ui, server)
# edit as a module
library(mapedit)
library(mapview)
library(shiny)
m = mapview(breweries91)@map
testsf = NULL
ui <- tagList(
editModUI("test-edit"),
h1("What You Draw"),
leafletOutput("edited")
)
server <- function(input, output, session) {
crud <- callModule(editMod, "test-edit", m, "breweries91")
output$edited <- renderLeaflet({
req(crud()$finished)
mapview(crud()$finished)@map
})
}
shinyApp(ui, server)
# editMap module can easily be combined to make a selection tool
# do selection of breweries with drawn polygons
library(sf)
library(mapview)
library(mapedit)
library(shiny)
ui <- fluidPage(
fluidRow(
column(6,editModUI("brew-select")),
column(6,leafletOutput("mapout"))
)
)
server <- function(input,output,session) {
m = mapview(breweries91)@map
brew_sf <- st_as_sf(breweries91)
drawn <- callModule(editMod, "brew-select", m)
calc_sf <- reactiveValues()
observe({
req(drawn()$finished)
calc_sf$intersection <- st_intersection(drawn()$finished, brew_sf)
})
output$mapout <- renderLeaflet({
req(calc_sf$intersection)
(mapview(calc_sf$intersection) + mapview(drawn()$finished))@map
})
}
shinyApp(ui,server)
}