我正在创建一个闪亮的应用程序,允许用户将数据写入 csv 或 kml。但是,我下面的代码不会将功能写入 kml 文件,因此当我在 google earth 中打开 KML 时,它会显示黑点,单击时会显示原始数据的行索引,而不是该特定数据的所有列值观点。我正在使用 writeOGR 函数,但它没有写入文件,所以我切换到使用 plotKML 包。我希望用户选择文件的保存位置(使用我指定的带有日期和时间戳的文件名)并在 Google 地球中显示任何给定数据点的所有功能。
output$downloadData <- downloadHandler(
filename = function() {
paste0("data_",Sys.Date(), input$download_type)
},
content = function(file) {
if (input$download_type == ".csv"){
write.csv(data, file, row.names = FALSE)
} else if (input$download_type == ".KML") {
features <- c("COLUMN_1", "COLUMN_2", "COLUMN_3") #These are the features I want displayed in Google Earth
data[features] <- as.character(data[features])
coordinates(data) <- ~X + Y
proj4string(data) <- CRS("+proj=longlat +datum=WGS84")
kml_description(data, caption = "Data",
delim.sign = "_", asText = F)
kml(data, file = file) #Not sure why this produces points but doesn't display features in Google Earth
#writeOGR(data, dsn = file, layer="Data", driver = "KML")
}
})