Skip to content

Commit

Permalink
isolated geolocated and input ids
Browse files Browse the repository at this point in the history
  • Loading branch information
fontikar committed Jun 12, 2024
1 parent c8bef18 commit 7804e40
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions R/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ load_place <- function(path) {
#' @return Circular polygon geometry.
#' @noRd
create_circle_polygon <- function(lat, long, radius_m) {

# Create a point in a geographical coordinate system (WGS 84)
pt <- sf::st_point(c(long, lat))
pt <- sf::st_sfc(pt, crs = 4326) # Assign WGS 84 CRS
Expand Down
37 changes: 32 additions & 5 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ infinity_server <- function(...) {

# Render coordinates text
output$lat <- renderText({
input$latitude
input$geolat
})

output$long <- renderText({
input$longitude
input$geolong
})

output$accuracy <- renderText({
Expand All @@ -63,7 +63,7 @@ infinity_server <- function(...) {
})


circle_polygon <- eventReactive(input$executeButton, {
circle_polygon_choose <- eventReactive(input$executeButton, {
lat <- tryCatch(
as.numeric(input$latitude),
error = function(e)
Expand All @@ -90,6 +90,33 @@ infinity_server <- function(...) {
})


circle_polygon_geo <-eventReactive(input$executeButton, {
lat <- tryCatch(
as.numeric(input$geolat),
error = function(e)
NA
)
long <-
tryCatch(
as.numeric(input$geolong),
error = function(e)
NA
)
radius_m <-
tryCatch(
as.numeric(input$radiusChoice),
error = function(e)
NA
)

if (is.na(lat) || is.na(long) || is.na(radius_m)) {
return(NULL)
}

return(create_circle_polygon(lat, long, radius_m))
})


selected_polygon <- reactive({
switch(
input$inputType,
Expand All @@ -98,11 +125,11 @@ infinity_server <- function(...) {
},

"choose" = {
return(circle_polygon())
return(circle_polygon_choose())
},

"current" = {
return(circle_polygon())
return(circle_polygon_geo())
},

"upload" = {
Expand Down
8 changes: 4 additions & 4 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ ui <- function(){
var coords = position.coords;
console.log(coords.latitude + ", " + coords.longitude, "," + coords.accuracy);
Shiny.onInputChange("geolocation", true);
Shiny.onInputChange("latitude", coords.latitude);
Shiny.onInputChange("longitude", coords.longitude);
Shiny.onInputChange("geolat", coords.latitude);
Shiny.onInputChange("geolong", coords.longitude);
Shiny.onInputChange("accuracy", coords.accuracy);
}, 1100)
}
Expand Down Expand Up @@ -120,14 +120,14 @@ ui <- function(){
numericInput(
"latitude",
"Latitude",
value = -33.8688,
value = -34.1182,
min = -90,
max = 90,
step = 0.00001),
numericInput(
"longitude",
"Longitude",
value = 148.2093,
value = 151.0636,
min = -180,
max = 180,
step = 0.00001
Expand Down

0 comments on commit 7804e40

Please sign in to comment.