dkahle / ggmap

A package for plotting maps in R with ggplot2
763 stars 231 forks source link

Stamen map not rendered in shiny -> receiving blank image #323

Open ghost opened 2 years ago

ghost commented 2 years ago

I try to build some simple stamenmaps with ggmap in R-Shiny. I can't seem to get the map rendered. I only receive a blank image. The the simple example attached below:

library(ggmap)
library(shiny) 

server <- function(input, output) {

    map_ren <- renderPlot(get_stamenmap(
        bbox = c(
            left = 10,
            bottom = 30,
            right = 42,
            top = 34),
        maptype = "terrain",
        zoom = 3,
        force = TRUE
    ), width = 1000, height = 1000)

    output$map <- map_ren
}

ui <- fluidPage(
        plotOutput('map', width = 1000, height = 1000)
)

shinyApp(ui, server)

}, si = TRUE)
ChristianSch commented 5 months ago

This is an old issue, but in any case: This has nothing to do with shiny, but with wrong usage.

You're missing the ggmap call:

library(ggmap)
library(shiny) 

server <- function(input, output) {
  map_ren <- renderPlot(
    ggmap(get_stadiamap(
    bbox = c(
      left = 10,
      bottom = 30,
      right = 42,
      top = 34),
    maptype = "alidade_smooth",
    zoom = 3,
    force = TRUE
  )), width = 1000, height = 1000)

  output$map <- map_ren
}

ui <- fluidPage(
  plotOutput('map', width = 1000, height = 1000)
)

shinyApp(ui, server)