使用传单和光泽显示地图时出现问题

时间:2019-07-14 23:55:59

标签: shiny leaflet maps

我想绘制某个国家/地区的犯罪数量,但要使用一个框来选择我要绘制的州。

我是新来的,我不知道为什么我遇到问题。 这是我的代码,您能帮我还是给我一些建议?

我看不到真正的问题,但我的闪亮应用程序未绘制任何地图

temper<- readOGR(".", layer = "Muni_2012gw", encoding = "UTF-8")
crimes<-read.xlsx("crime_may.xlsx",sheet=1, startRow = 1, colNames = TRUE, rowNames = FALSE)
id_crime<-c("one","two","three")

crimes<-subset(crimes,Mod %in% id_crime)
#unique(crimes$Mod)
crimes<- crimes[,colSums(is.na(crimes))<nrow(crimes)]

mth<-10+month(Sys.Date())-3

crimes<-transform(crimes,Total_crimes=rowSums(crimes[,10:mth]))

crimes$Ky..Mun<-ifelse(crimes$Ky_state<10,paste0('0',crimes$Ky..Mun),crimes$Ky..Mun)
crimes$Ky_state<-ifelse(crimes$Ky_state<10,paste0('0',crimes$Ky_state),crimes$Ky_state)
agg<-aggregate(crimes$Total_crimes,list(crimes$Ky_state,crimes$st,crimes$Ky..Mun ,crimes$Mun),sum)
colnames(agg)<-c("Ky_state",'State','KEY','Mun','Total_crimes')
#head(agg)
#head(temper@data)

states<-data.frame(unique(crimes[,c("State","Ky_state")]), row.names = NULL)

temper@data$KEY<-paste0(temper@data$Ky_state,temper@data$KY_MUN)

choices<-setNames(states$Ky_state,states$State)
# Define UI for application that draws a histogram
ui <- fluidPage(

  # Copy the line below to make a select box 


  selectInput("stt", label = h3("State:"), 
              choices = choices, 
              selected = "AG"),

  hr(),
  fluidRow(column(3, verbatimTextOutput("value")))


)

# Define server logic required to draw a histogram
server <- function(input, output) {
   filtered_data<-reactive({
     S_MPOSv<-subset(temper, temper@data$CVE_ENT=='09') 

     agg1<-subset(agg,Ky_state=='09') 

     S_MPOSv1<-join(S_MPOSv@data,agg1) 

     S_MPOSv$Total_crimes<-S_MPOSv1$Total_crimes

     S_MPOSv

  } )


  pal <- colorNumeric("YlGn", NULL, n =10 ) 


  state_popup <- reactive({paste0("<strong>MUN: </strong>", 
                        S_MPOSv$NOM_MUN, 
                        "<br><strong>Num. crimes: </strong>", 
                        S_MPOSv$Total_crimes)})

  #data_map<-reactive({S_MPOSv$Total_crimes})
  output$mymap <- renderLeaflet(

    {

    leaflet(data = S_MPOSv) %>%
      addProviderTiles("CartoDB.Positron") %>%
      addPolygons(fillColor = ~pal(S_MPOSv$Total_crimes), 
                  fillOpacity = 0.9, 
                  color = "#BDBDC3",
                  weight = 1, 
                  popup = state_popup)
 } )

}

# Run the application 
shinyApp(ui = ui, server = server)

该应用仅显示我在ui上设置的“选择菜单”,但没有显示我的地图

0 个答案:

没有答案