【问题标题】:Error in Shiny while using stamen maps - "Object not found"使用雄蕊图时 Shiny 出错 - “找不到对象”
【发布时间】:2021-09-03 09:21:22
【问题描述】:

我通常是使用 Shiny 和 R 编程的新手。我试图使用雄蕊图创建一个闪亮的应用程序,并将函数 get_stamenmap 与边界框和其他参数一起使用。我将此函数分配给 ggmap 函数中的变量“map”。

我收到一个错误:

收听http://127.0.0.1:5907 警告:ggmap 中的错误:找不到对象“地图” 52:地图 49:服务器 [#2] ggmap(map) 中的错误:找不到对象“map”

我使用的代码:

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")
  
}

【问题讨论】:

  • 在结尾“}”之前是否只缺少一个“)”?

标签: r shiny stamen-maps


【解决方案1】:

您很可能缺少/放错了括号。试试这个

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")
  })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多