Shiny App with OSM Data

Hi,
I have a leaflet map that is powered by osmdata. I have tried to apply this in a shiny app. The app runs but the map does not appear.

library(osmdata)
library (sf)
library(rgdal)
library(leaflet)
x <-opq(bbox=c(-3.845215,51.041394,4.658203,58.642653),timeout = 25*1000)%>%
  add_osm_feature("plant:source","wind") %>%
  osmdata_sf()

ui <- fluidPage(
  mainPanel(leafletOutput("myMap")),
  headerPanel("Asset Header"),
  sidebarPanel()
)

server<-function(input,output){

output$map<-renderLeaflet
({
                          map= leaflet()%>%addTiles()%>%addPolygons(data=x,
                          popup = paste("Name:",x$Project.Name,"<br/>"))

  output$myMap = renderLeaflet(map)
                          })
                       }
          
shinyApp(ui = ui, server = server)

Is there a reason the leaflet map does not appear?
Should I query osm everytime or should I save the data locally via *.rds?

Thanks

Hi - I found the answer and solution to my issue from:

Shiny is already establishing a URL connection between a server (in this case your computer is being used as a server as the app is located there) and the browser, and you are allowed to create more direct connections within shiny, but OSMdata, sends a query to the Overpass Turbo service (the overpass turbo translate your query from a scripting language to a compact format, for the API to understand it) then the overpass turbo sends the translated query to the overpass API and the overpass API send the results back to us.

For our shiny app to work properly, we need to get rid of the intermediate step and do a direct query to the overpass API.

I hope others find this question useful

2 Likes

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.