单张/发光:无法绘制反应性多边形 [英] Leaflet/shiny: cannot draw reactive polygons

查看:70
本文介绍了单张/发光:无法绘制反应性多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览了 R的Leaflet页面上的发光集成示例,我在设置子集和显示一些多边形以在我的闪亮应用程序中显示时遇到了麻烦.

Having looked through the Shiny integration example on the Leaflet for R page, I am having trouble subsetting and displaying some polygons for display in my shiny app.

此刻,我正在获取一个带有侧边栏的应用程序,但主要显示只是错误:不知道如何从反应性类的对象获取路径数据"

At the moment, i'm getting a app, with sidebar, but the main display is simply "Error:Don't know how to get path data from object of class reactive"

想法是从GB(3个国家/地区)中选择一个国家/地区多边形,并根据下拉选项单独显示;

The idea is to pick a country polygon from GB (3 countries) and display it alone, depending on the drop down choice;

require(shiny)
require(rgdal)
require(rgeos)
require(leaflet)

cont <- readOGR(".\\mypath\\mypolygons.shp", "mypolygons", stringsAsFactors=FALSE)

ui <- fluidPage(

  titlePanel("My page"),

  sidebarLayout(
    sidebarPanel(
      selectInput("countryInput", "Country:", choices = c('England','Scotland','Wales'))
    ),
    mainPanel(
      leafletOutput("mymap")
    )
  )
)

server <- function(input, output, session) {

pols <- eventReactive(input$countryInput,{cont[substr(cont@data$code,1,1)==substr(input$countryInput,1,1),]})

  output$mymap <- renderLeaflet({
    leaflet() %>%
      addProviderTiles("CartoDB.Positron") %>%
      addPolygons(data = pols)
  })
}


shinyApp(ui, server)

错误:

Warning: Error in polygonData.default: Don't know how to get path data from object of class reactive
Stack trace (innermost first):
    83: polygonData.default
    82: polygonData
    81: derivePolygons
    80: addPolygons
    79: function_list[[k]]
    78: withVisible
    77: freduce
    76: _fseq
    75: eval
    74: eval
    73: withVisible
    72: %>%
    71: func [#6]
    70: output$mymap
     4: <Anonymous>
     3: do.call
     2: print.shiny.appobj
     1: <Promise>

推荐答案

修复:

首先我改变了

pols <- eventReactive(input$countryInput,{cont[substr(cont@data$code,1,1)==substr(input$countryInput,1,1),]})

到;

pols <- reactive({cont.sim[substr(cont.sim@data$gssCode,1,1)==substr(input$countryInput,1,1),]

并且'addPolygons行在变量名'pols'之后缺少左/右括号

and the 'addPolygons line was missing the open/close brackets after the variable name 'pols'

addPolygons(data = pols)

成为

addPolygons(data = pols())

这篇关于单张/发光:无法绘制反应性多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆