-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
122 lines (93 loc) · 3.73 KB
/
app.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
library(shiny)
library(leaflet)
# Read the data
source("leitura_dados.R")
# Define UI for application that draws a map
ui <- fluidPage(
navbarPage("Mapa", id="nav",
tabPanel("Mapa Interativo",
div(class="outer",
tags$head(
#Include our custom CSS
includeCSS("styles.css"),
#includeScript("gomap.js")
),
leafletOutput("map", width="100%", height="100%"),
absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
width = 330, height = "auto",
h2("Mapa de pontos de interesse dos alunos em Osasco(SP)"),
)
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
## Interactive Map ###########################################
# Create the map
output$map <- renderLeaflet({
leaflet() %>%
addTiles(attribution = ' Osasco ') %>%
setView(lng = -46.7685951, lat = -23.5061744, zoom = 15)
})
# This observer is responsible for maintaining the circles and legend,
# according to the variables the user has chosen to map to color and size.
observe({
getColor <- function(df) {
sapply(df$tipo, function(tipo) {
if(tipo == "DESGASTE_SAUDE") {
"green"
} else if(tipo == "TRABALHO") {
"orange"
} else {
"red"
} })
}
icons <- awesomeIcons(
icon = 'ios-close',
iconColor = 'black',
library = 'ion',
markerColor = getColor(df)
)
scaleBarOptions(maxWidth = 100, metric = TRUE, imperial = FALSE,
updateWhenIdle = TRUE)
leafletProxy("map", data = df) %>%
clearMarkers() %>%
addAwesomeMarkers(~Longitude, ~Latitude, label = ~Nome, icon = icons) %>%
addLegend("bottomright",labels = levels(df$tipo), colors = c("red", "green", "orange" )) %>%
addScaleBar(position = "bottomleft", options = scaleBarOptions())
})
#funcao que mostra a cidade clicada
showPopup <- function(lat, lng) {
selectedZip <- df %>% filter(Latitude == lat & Longitude == lng)
content <- as.character(tagList(
tags$h4(HTML(sprintf("%s",
selectedZip$Nome
))),
sprintf("Endereco: %s", selectedZip$ENDERECO),tags$br(),
sprintf("Ocorrência: %s", selectedZip$OCORRENCIA),tags$br()
))
leafletProxy("map") %>% addPopups(lng, lat, content)
}
#observador que mostra a cidade clicada
observe({
leafletProxy("map") %>% clearPopups()
event <- input$map_marker_click
if (is.null(event))
return()
isolate({
showPopup(event$lat, event$lng)
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
#rsconnect::deployApp(account = "chicodias")