【问题标题】:R Error in get: object '.xts_chob' not foundR获取错误:找不到对象'.xts_chob'
【发布时间】:2017-12-19 06:29:07
【问题描述】:

我正在尝试执行以下代码 -

library(dplyr) ; library(rgdal) ; library(leaflet);
crimes <- read.csv("crime_data.csv", header = T) %>% 
  filter(borough == "Manchester",
         date == "2015-11-01") %>% 
  group_by(category, lsoa, borough) %>%
  summarise(n = n()) %>% 
  rename(LSOA11CD = lsoa) %>% 
  as.data.frame()
lsoa <- readOGR("manchester_lsoa.geojson", "OGRGeoJSON")
ui <- shinyUI(fluidPage(
  fluidRow(
    column(7, offset = 1,
           br(),
           div(h4(textOutput("title"), align = "center"), style = "color:black"),
           div(h5(textOutput("period"), align = "center"), style = "color:black"),
           br())),
  fluidRow(
    column(7, offset = 1,
           leafletOutput("map", height="530"),
           br(),
           actionButton("reset_button", "Reset view")),
    column(3,
           uiOutput("category", align = "left")))
))
server <- (function(input, output, session) {
  output$category <- renderUI({
    radioButtons("category", "Select a crime category:",
                 choices = levels(crimes$category),
                 selected = "Burglary")
  })
  selected <- reactive({
    subset(crimes,
           category==input$category)
  })
  output$title <- renderText({
    req(input$category)
    paste0(input$category, " offences by LSOA in Manchester")
  })
  output$period <- renderText({
    req(input$category)
    paste("during November 2015")
  })
  lat <- 53.442788; lng <- -2.244708; zoom <- 11
  output$map <- renderLeaflet({
    leaflet() %>% 
      addProviderTiles("CartoDB.Positron") %>% 
      setView(lat = lat, lng = lng, zoom = zoom)
  })
  observe({
    lsoa@data <- left_join(lsoa@data, selected())
    lsoa$rate <- round((lsoa$n / lsoa$pop_All.Ag) * 1000, 1)
    qpal <- colorQuantile("YlGn", lsoa$rate, n = 5, na.color = "#bdbdbd")
    popup <- paste0("<strong>LSOA: </strong>",
                    lsoa$LSOA11CD,
                    "<br><strong>Category: </strong>",
                    lsoa$category,
                    "<br><strong>Rate: </strong>",
                    lsoa$rate)
    leafletProxy("map", data = lsoa) %>%
      addProviderTiles("CartoDB.Positron") %>% 
      clearShapes() %>% 
      clearControls() %>% 
      addPolygons(data = lsoa, fillColor = ~qpal(rate), fillOpacity = 0.7, 
                  color = "white", weight = 2, popup = popup) %>%
      addLegend(pal = qpal, values = ~rate, opacity = 0.7,
                position = 'bottomright', 
                title = paste0(input$category, "<br>", " per 1,000 population"))
  })
  observe({
    input$reset_button
    leafletProxy("map") %>% setView(lat = lat, lng = lng, zoom = zoom)
  })      
})
shinyApp(ui, server)

我得到了这个错误

Warning in is.na(e2) :
  is.na() applied to non-(list or vector) of type 'NULL'
Joining, by = "LSOA11CD"
Warning: Column `LSOA11CD` joining factors with different levels, coercing to character vector
Warning: Error in get: object '.xts_chob' not found
ERROR: [on_request_read] connection reset by peer

所需文件的链接是thisthis

谁能告诉我错误是什么?错误是由于传单包装吗?还是因为其他包?还有谁能给我解决这个错误的方法吗?

【问题讨论】:

    标签: r shiny leaflet rgdal


    【解决方案1】:

    这可能是命名空间问题。 xts 库是否已加载?我有一个类似的问题,并通过从传单中显式调用 addLegend 来修复它:

    leaflet::addLegend(pal = qpal, values = ~rate, opacity = 0.7,
                       position = 'bottomright', 
                       title = paste0(input$category, "<br>", " per 1,000 population"))
    

    【讨论】:

      【解决方案2】:

      使用旧版本的“xts”进行探测,例如安装 0.9 版:

      require(devtools)
      install_version("xts", version = "0.9-7", repos = "http://cran.us.r-project.org")
      

      【讨论】:

        【解决方案3】:

        它的包装和闪亮的东西。诀窍是安装其中一个并使用:: 表示法从另一个调用函数。所以我主要需要闪亮所以包被加载然后我使用它的功能符号:

        temp.data <- xts::as.xts(df2, order.by = df2$day)
        

        【讨论】:

          【解决方案4】:

          我遇到了同样的问题。因此,我安装了新版本的xts 并重新启动了 R 会话。

          【讨论】:

            猜你喜欢
            • 2017-06-12
            • 2018-08-15
            • 2019-01-18
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-04-13
            • 2023-03-24
            • 1970-01-01
            相关资源
            最近更新 更多