bcgov / shinyrems

An R package to launch shinyrems; an online application that allows a user to access, download, clean, plot and calculate simple statistics using data from the B.C. government Environmental Monitoring System database.
https://bcgov.github.io/shinyrems/
Other
18 stars 4 forks source link

Summary table bug on Plot/Statistics tab #139

Open aylapear opened 2 years ago

aylapear commented 2 years ago

Was unsure if I introduced bug while fixing other parts but check by switching to a previous SHA before I did any work and the bug is still present. When you click on the summary tab in Tab 5 Plot/Statistics the app throws an error. Tried various stations-variable combinations and it throws the error. The error is pasted below

Warning in survreg.fit(X, Y, weights, offset, init = init, controlvals = control,  :
  Ran out of iterations and did not converge
Warning: Error in <-: 'names' attribute [4] must be the same length as the vector [0]
  138: .local
  137: mean
  135: .fun
  134: <Anonymous>
  132: llply
  131: ldply
  130: plyr::ddply
  129: wqbc::summarise_wqdata
  124: <reactive> [/Users/aylapearson/Applications/shinyrems/R/mod_results.R#188]
  108: summary_table
  105: exprFunc [/Users/aylapearson/Applications/shinyrems/R/mod_results.R#199]
  104: widgetFunc
  103: ::
htmlwidgets
shinyRenderWidget
  102: func
   89: renderFunc
   88: renderFunc
   84: renderFunc
   83: output$results_ui_1-table
    2: shiny::runApp
    1: shinyrems::run_ems_app [/Users/aylapearson/Applications/shinyrems/R/run_app.R#71]
aylapear commented 2 years ago

Issue related to wqbc https://github.com/bcgov/wqbc/issues/163

aylapear commented 1 year ago

This is occurring due to the edge cases when all the values are censored or only a single value remains for the site. I think that we can change the function to output NA's instead of an error message. That will allow sites/chemicals that have no values to have NA's displayed in the row and not cause an error so the table can generate.

aylapear commented 1 year ago

Instead of an error that causes the whole tab to fail you would generate a table like this that displays each site/chemical

# A tibble: 2 × 14
  Variable       EMS_ID      n  ncen   min   max  mean median lowerQ upperQ     sd     se lowerCL upperCL
  <chr>          <chr>   <int> <int> <dbl> <dbl> <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>   <dbl>   <dbl>
1 Nitrogen Total 0200016     3     0 0.754 0.949 0.849  0.845  0.793  0.901 0.0799 0.0461   0.763   0.944
1 Nitrogen Total 0478416     NA          NA      NA      NA       NA       NA      NA        NA       NA        NA        NA
aylapear commented 1 year ago

Updates to wqbc now allow the Summary Table tab under the Plot/Statistics section to work and not error out when some of the sites do not have a calculated summary.

Screenshot 2022-12-30 at 8 05 22 PM