简体   繁体   中英

R Error in get: object '.xts_chob' not found

I am trying to execute the following code -

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)

and I get this error

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

The links to the required files are this and this

Can someone please tell me what the error is? Is the error due to leaflet package? Or is it because of other packages? And also can someone give me the solution to the error as well?

It could be a namespace issue. Is the xts library loaded? I've had a similar issue and fixed it by calling addLegend from leaflet explicitly:

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

Probe using an old version of 'xts', for example install the version 0.9:

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

It is a stuff up with the its package and shiny. The trick is to install one of these and use the :: notation to call functions from the other. So I mainly need shiny so the package is loaded then I use the notation for its functions:

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

I got the same problem. So, I install a new version of xts and restart the R session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM