LandSciTech / ccviR

Implement NatureServe climate change vulnerability index in R
https://landscitech.github.io/ccviR/
Other
2 stars 2 forks source link

Account for missing data when calculating index #143

Closed adricaswell closed 7 months ago

adricaswell commented 7 months ago

Running calculate index (in the index results tab) without having input anything will result in the following error and cause the app to grey out:

Warning: Error in : spat_df is missing the required columns: MAT_1, MAT_2, MAT_3, MAT_4, MAT_5, MAT_6, CMD_1, CMD_2, CMD_3, CMD_4, CMD_5, CMD_6, CCEI_1, CCEI_2, CCEI_3, CCEI_4, HTN_1, HTN_2, HTN_3, HTN_4, PTN, MAP_max, MAP_min, range_change, range_overlap, range_size
  3: runApp
  2: print.shiny.appobj
  1: <Anonymous>

This error appears before receiving the spat out_data message.

I believe that the code below (taken from line 1426 of ccvi_app.R) initiates this error as spat_res() is missing. However, this error isn't handled, causing the app to crash.

req(spat_res())
req(clim_readme())
req(!is.null(file_pths()))

Need to add the handle the error. Maybe by wrapping in an if statement? Or adding try()? if(is.null(req(spat_res())) || is.null(req(clim_readme())) || is.null(req(!is.null(file_pths())))

see24 commented 7 months ago

actually req is supposed to prevent the rest of that section of code from running unless spat_res is available. But it doesn't seem to be working correctly so I will look into that.