Rajiv Manuel
Rajiv Manuel

Reputation: 5

Error in Shiny while using stamen maps - "Object not found"

I am new to using Shiny and R programming in general. I was trying to create a Shiny app using stamen maps and used the function get_stamenmap with bounding box and other arguments. I assigned this function to a variable 'map' in the ggmap function.

I am getting an error :

Listening on http://127.0.0.1:5907 Warning: Error in ggmap: object 'map' not found 52: ggmap 49: server [#2] Error in ggmap(map) : object 'map' not found

The code I used:

ui <- fluidPage(
  mainPanel("Siebar"),
  sidebarLayout(
    sidebarPanel("Options",
                 radioButtons(inputId = "radio",
                              label = "Type of Offense",
                              choices = list("Murder" = 'murder',
                                             "Robbery" = 'robbery',
                                             "Assault" = 'aggravated assault',
                                             "Burglary" = 'burglary',
                                             "Auto-Theft" = 'auto theft',
                                             "Theft" = 'theft',
                                             "Rape" = 'rape'),
                              selected = 'murder'),
                 
                 
                 ),
  mainPanel(
    plotOutput('plot')
  ),
)
)
server <- function(input, output){
  output$plot <- renderPlot(
    map <- get_stamenmap(bbox = c(left=-95.8, bottom=29.4, right=-95.0, top=30.0), 
                         zoom = 10, source = "stamen", maptype = "terrain"),
    ggmap(map) + stat_density_2d(data = subset(crime, offense == input$radio)),
    aes(x = lon, y = lat, fill = ..level.., alpha = ..level..), geom = 'polygon') +
    ggtitle("Crimes in Houston, TX")
  
}

Upvotes: 0

Views: 140

Answers (1)

YBS
YBS

Reputation: 21297

Most likely you have missing/misplaced brackets. Try this

server <- function(input, output){
  output$plot <- renderPlot({
    map <- get_stamenmap(bbox = c(left=-95.8, bottom=29.4, right=-95.0, top=30.0), 
                         zoom = 10, source = "stamen", maptype = "terrain")
    
    ggmap(map) + 
      stat_density_2d(data = subset(crime, offense == input$radio),
                      aes(x = lon, y = lat, fill = ..level.., alpha = ..level..), geom = 'polygon') +
      ggtitle("Crimes in Houston, TX")
  })
}

output

Upvotes: 0

Related Questions