【问题标题】:Trying to render ggmap plot in R Shiny dynamically but receiving only blank image试图在 R Shiny 中动态渲染 ggmap 图但只接收空白图像
【发布时间】:2021-10-07 02:56:38
【问题描述】:

我正在开发用于地理分析的复杂 R-Shiny 应用程序。作为其中的一部分,我想动态渲染一个 ggmap stemen 地图。因此,我向用户询问 Openstreetmap 导出数据(缩放、左、右...参见here)。单击按钮,我想构建和渲染地图。不幸的是,唯一发生的事情是我得到一个空白图像。如果我使用绘图功能在 RStudio 中渲染地图,我可以看到绘图。

要绘制地图,我需要进行哪些更改?

library(ggplot2)
library(ggmap)
library(shiny)

server <- function(input, output) {
    
    observeEvent(input$show_map, {
        
        box <- c(
            left = input$left,
            bottom = input$bottom,
            right = input$right,
            top = input$top)
        
        map <- get_stamenmap(
            bbox = box,
            maptype = "terrain",
            zoom = input$zoom
        )
        plot(map) #plot in RStudio
        output$point_map <- renderPlot(map)
    })
    
}

ui <- fluidPage(
    sidebarPanel(
        numericInput("top", "North", value = "55.159", width = 75),
        numericInput("bottom", "South", value = "47.2", width = 75),
        numericInput("left", "West", value = "5.768", width = 75),
        numericInput("right", "East", value = "15.216", width = 75),
        numericInput("zoom", "Zoom", value = "7", width = 75, min = 0, max = 18),
        actionButton("show_map", "Show map!")),
    mainPanel(
        plotOutput('point_map')
    )
)

shinyApp(ui, server)

提前感谢您的帮助!

【问题讨论】:

    标签: r ggplot2 shiny gis ggmap


    【解决方案1】:

    要实际绘制地图,您必须调用 ggmap(map) 或 plot(map),即这样做

    output$point_map <- renderPlot(ggmap(map))
    

    或

    output$point_map <- renderPlot(plot(map))
    

    在您的应用中。

    【讨论】:

      猜你喜欢
      • 2020-04-04
      • 2020-11-08
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      相关资源
      最近更新 更多