使用R语言nestR包调用explore_nests时Shiny应用报错求助
解决nestR包explore_nests函数Shiny界面报错问题
问题背景
使用nestR包处理鸟类GPS数据寻找潜在鸟巢,已准备符合要求的4列CSV数据(burst固定为1、date为POSIXt格式、long经度、lat纬度),find_nests函数运行正常并返回包含nests和visits的列表,但调用explore_nests时出现Shiny界面空白、无法选择burst,点击后报错;尝试传入ws_output_1[[1]]仍触发字段缺失报错。
报错原因分析
- 首次报错
no applicable method for 'filter' applied to an object of class "list":explore_nests不接受find_nests返回的列表类型输入,它需要的是原始GPS数据框。 - 二次报错
Data does not include required fields:ws_output_1[[1]]是find_nests识别出的鸟巢结果数据框,缺少原始GPS数据的时间序列等必要字段,不符合explore_nests的输入要求。
解决方案
1. 确保原始数据格式正确
read.csv会将date列读为字符型,需手动转换为POSIXt格式:
setwd("I:/R TESTS") library(nestR) library(dplyr) # 读取并处理原始数据 X154 <- read.csv("X154.csv") # 转换date列为POSIXt,根据数据实际时区调整tz参数(示例用UTC) X154$date <- as.POSIXct(X154$date, tz = "UTC")
2. 传入原始GPS数据调用explore_nests
直接将处理好的原始GPS数据传入函数,Shiny界面会自动加载burst选项并支持参数配置:
# 基础调用,界面内手动设置参数 explore_nests(gps_data = X154) # 或预设与find_nests相同的参数,避免重复输入 explore_nests(gps_data = X154, sea_start = "05-02", sea_end = "06-01", nest_cycle = 30, buffer = 40, min_pts = 2, min_d_fix = 1, min_consec = 2, min_top_att = 1, min_days_att = 1, discard_overlapping = FALSE)
关键说明
explore_nests的设计逻辑是基于原始GPS数据在Shiny交互界面内重新执行鸟巢识别流程,因此必须传入包含burst、date、long、lat的原始数据框,而非find_nests的输出结果。
内容的提问来源于stack exchange,提问作者Takis Pitsakis
相关产品推荐
相关产品推荐

