Q:

R Shiny: Get longitude and latitude of a country

I want to get longitude and latitude for a particular country so that I can zoom to that country in the map. I am using leaflet in shiny.I know I can use "setView( longitude , latitude, zoom = 4)". But how do I get the longitude and latitude of the country?
I have written the following code so far:
library(shiny)
library(leaflet)

ui <- fluidPage(

   leafletOutput("CountryMap", width = 1000, height = 500)
)

server <- function(input, output){

   Country = map("world", fill = TRUE, plot = FALSE, regions="USA")
   output$CountryMap <- renderLeaflet({

  leaflet(Country) %>% addTiles() %>%  setView( 0 , 0, zoom = 4)%>%
   addPolygons(fillOpacity = 0.6,  smoothFactor = 0.5, stroke = TRUE, weight = 1)
})
}

shinyApp(ui =ui, server = server)

A:

I wanted to zoom in to a country. So I found a better way to do it. Using   fitBounds(map, lng1, lat1, lng2, lat2)
The code is as follows:
library(shiny)
library(leaflet)
library(maps)

ui <- fluidPage(

  leafletOutput("CountryMap", width = 1000, height = 500)
)

server <- function(input, output){

 Country = map("world", fill = TRUE, plot = FALSE, regions="USA", exact=TRUE)
 output$CountryMap <- renderLeaflet({
     leaflet(Country) %>% addTiles() %>%
     fitBounds(Country$range[1], Country$range[3], Country$range[2], Country$range[4])%>%
     addPolygons(fillOpacity = 0.6,  smoothFactor = 0.5, stroke = TRUE, weight = 1)
})
}

shinyApp(ui =ui, server = server)

