-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
54 lines (43 loc) · 1.02 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
library(shiny)
library(shinyjs)
source("googlemap_autocomplete.R")
ui <- fluidPage(
useShinyjs(),
includeCSS("www/custom.css"),
googlemap_autocomplete_ui(
"test",
width = "100%",
key = Sys.getenv("GCP_TOKEN_MAPS")
),
leaflet::leafletOutput(
"map",
width = "auto",
height = "auto"
)
)
server <- function(input, output, session) {
address <- googlemap_autocomplete_server(
"teste",
key = Sys.getenv("GCP_TOKEN_MAPS")
)
output$map <- leaflet::renderLeaflet({
shiny::req(address())
shinyjs::runjs('$("#map").width(500).height(500);')
results <- address()[["results"]]
lng <- results[["geometry"]][["location"]][["lng"]]
lat <- results[["geometry"]][["location"]][["lat"]]
leaflet::leaflet() |>
leaflet::addTiles() |>
leaflet::setView(
lng = lng,
lat = lat,
zoom = 13
) |>
leaflet::addMarkers(
lng = lng,
lat = lat,
popup = "Well done, noble warrior!"
)
})
}
shinyApp(ui, server)