הדפסת אובייקטים על מפה באפליקציית shiny מתוך כפתור

13 views
Skip to first unread message

Lior Smadja

unread,
Jun 8, 2018, 4:36:12 AM6/8/18
to Israel R User Group

שלום לכולם ,

אני מנסה להדפיס נתונים בפונקציית addMarkers תחת כפתור observeEvent , הנתונים מאוחסנים בתוך data.frame . כאשר אני מבצע הדפסה לתוך מפה , אני נתקל בשגיאה הבאה :

Warning: Error in : $ operator is invalid for atomic vectors
Stack trace (innermost first):
81: packStrings
80: b64EncodePackedIcons
79: addMarkers
78: func
77: origRenderFunc
76: output$m
1: runApp

הקטע קוד המלא של הכפתור הוא :

observeEvent(input$test199,{ 
dd<-read.csv("C:/project stat/final project/dynamics_icons1.csv",stringsAsFactors = FALSE)
Countrows<-length(count.fields("C:/project stat/final project/dynamics_icons1.csv", skip = 1))
dd$Lat<-runif(Countrows,min=31.539633,max=31.588778) 
dd$Lon<-runif(Countrows,min=34.221401,max=34.491940)
dd$Lon_poly<-runif(Countrows,min=34.221401,max=34.491940)
dd$Lat_poly<-runif(Countrows,min=31.539633,max=31.588778)
dd$Radius<-runif(Countrows,min=1,max=4)
dt <- expand.grid.df(dd,dd)
names(dt)[11:12] <- c("Lat_poly","Lon_poly")
xx<-setDT(dt)[ , dist_met := distGeo(matrix(c(Lon, Lat), ncol = 2), 
matrix(c(Lon_poly, Lat_poly), ncol = 2))/10000]
print(xx)
countrows_Matrix<- NROW(xx)
for (i in 1: countrows_Matrix){
ifelse (xx$dist_met[i] < xx$Radius[i],xx$in_out[i]<-1,xx$in_out[i]<-0)}
print(xx)
xx$new_lat=0
xx$new_lon=0
print(xx)
for (i in 1: countrows_Matrix){
ifelse(xx$in_out[i]==1 ,xx$new_lat[i]<-xx$Lat[i],xx$new_lat[i]<-NA )}
for (i in 1: countrows_Matrix){
ifelse(xx$in_out[i]==1 ,xx$new_lon[i]<-xx$Lon[i],xx$new_lon[i]<-NA )}
print(xx)
xxxx<-data.frame(lat=xx$new_lat,lng=xx$new_lon,icon=xx$icon)
output$m <- renderLeaflet(
m<- addMarkers(m,data=xxxx,lat=xxxx$new_lat,lng=xxxx$new_lon,icon=icon))

})


כאשר m הוא המפה.

אשמח לעזרה.

תודה מראש!

Reply all
Reply to author
Forward
0 new messages