CalCOFI / SaferSeafood

Repository containing files and data for developing the R Shiny online application.
https://shiny.calcofi.io/SaferSeafood
0 stars 1 forks source link

Error in rbind.data.frame(...) : numbers of columns of arguments do not match #9

Closed bbest closed 2 days ago

bbest commented 2 days ago

Hi @lmcgill,

I just merged your pull request #8 without checking and the app seems to have an error...

shiny::runApp('shinydashboard')
Loading required package: shiny
Reading layer `cinms_py' from data source 
  `/share/github/SaferSeafood/shinydashboard/data/polygons/cinms_py2' 
  using driver `ESRI Shapefile'
Simple feature collection with 2 features and 4 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -120.6421 ymin: 33.36241 xmax: -118.9071 ymax: 34.20707
Geodetic CRS:  NAD83
Error in rbind.data.frame(...) : 
  numbers of columns of arguments do not match
traceback()
16: stop("numbers of columns of arguments do not match")
15: rbind.data.frame(...)
14: st_sf(rbind.data.frame(...), crs = st_crs(dots[[1]]), sf_column_name = sf_column)
13: rbind(deparse.level, ...)
12: rbind(ventura, smbeach, sbpier, sandiego, mission, cacoastal)
11: dplyr::select(., Name, geometry)
10: rbind(ventura, smbeach, sbpier, sandiego, mission, cacoastal) %>% 
        dplyr::select(Name, geometry)
9: ..stacktraceon..({
       suppressPackageStartupMessages({
           library(shiny)
           library(shinydashboard)
           library(shinyjs)
           library(shinyWidgets)
           library(shinyBS)
           library(leaflet)
           library(leaflet.extras)
           library(shinycssloaders)
           library(extrafont)
           library(showtext)
           library(markdown)
           library(rfishbase)
           library(sf)
           library(skimr)
           library(tidymodels)
           library(caret)
           library(corrplot)
           library(sjPlot)
    ...
8: eval(exprs, envir)
7: eval(exprs, envir)
6: sourceUTF8(basename(globalPath), envir = globalrenv)
5: force(code)
4: withr::with_dir(appDir, {
       sourceUTF8(basename(globalPath), envir = globalrenv)
   })
3: loadSupport(appDir, renv = sharedEnv, globalrenv = globalenv())
2: appParts$onStart()
1: shiny::runApp("shinydashboard")

The problem looks to be in this statement, which I'll investigate further:

https://github.com/CalCOFI/SaferSeafood/blob/ec283ed98cb7b63bb3268c167a4ee2e30c748b76/shinydashboard/global.R#L102

bbest commented 2 days ago

Ok, fixed by swapping rbind() with bind_rows():

https://github.com/CalCOFI/SaferSeafood/blob/ca34c9960670a05036715896e7a305169d5e7ba7/shinydashboard/global.R#L102

Per `dplyr::bind_rows() documentation:

Bind any number of data frames by row, making a longer result. This is similar to do.call(rbind, dfs), but the output will contain all columns that appear in any of the inputs.