AmyMikhail / Geomapcoder

Multilingual shiny app to find and geocode postal addresses on a map
GNU General Public License v3.0
3 stars 2 forks source link

App failing to show browser for shapefile folder selection #1

Closed AmyMikhail closed 1 year ago

AmyMikhail commented 1 year ago

Problem statement:

When the app is launched and the button to include region borders is ticked, the second button to browse for the location of shapefiles is shown. However, when that button is clicked, the browser window fails to show, the app aborts and the following warning is shown in the R console:

Warning: Error in if: argument is of length zero
  1: runApp
Warning: Error in if: argument is of length zero
  1: runApp
Warning: Error in if: argument is of length zero
  1: runApp

Further details:

It is noteworthy that this warning is appearing three times... not really clear why this error is occuring, needs more debugging.

See image below:

image

AmyMikhail commented 1 year ago

Solution from Lucca Nielsen:

The issue is that file_selected() could be empty when the event was triggered, and the code didn’t handle this situation properly.

To fix this error, we need to ensure that file_selected() is not empty before trying to access its elements.

user_shp <- eventReactive(input$addshapefile, {
  if (!is.null(file_selected()) &&
      nrow(file_selected()) > 0 &&
      file.exists(file_selected()$datapath)) {

    sf::st_read(dsn = file_selected()$datapath)

  } else {
   NULL
  }
})