0

Usually when st_read is used you put path in dsn, but in case of shiny if you put a full path inside dsn it will give an error as that file path does not exist on the server. So, now I put the shapefile in the www folder, but I don't know what path to put in dsn so that the app picks up the shapefile.

How can I fix this?

Current function code in the app:

rocks_utm_sf = st_read(dsn = "D:/Sedimentary_Data_Analysis/www",layer = "Sed_UTM")

Below error in the log breaks the app

    021-10-02T19:05:08.733697+00:00 shinyapps[4783188]: Server version: 1.8.6.1
2021-10-02T19:05:08.733707+00:00 shinyapps[4783188]: R version: 4.0.2
2021-10-02T19:05:08.733705+00:00 shinyapps[4783188]: LANG: en_US.UTF-8
2021-10-02T19:05:08.725767+00:00 shinyapps[4783188]: Running on host: 52b53ce9aed0
2021-10-02T19:05:08.733716+00:00 shinyapps[4783188]: shiny version: 1.6.0
2021-10-02T19:05:08.733732+00:00 shinyapps[4783188]: httpuv version: 1.6.1
2021-10-02T19:05:08.931183+00:00 shinyapps[4783188]: Using jsonlite for JSON processing
2021-10-02T19:05:08.934357+00:00 shinyapps[4783188]: 
2021-10-02T19:05:08.733977+00:00 shinyapps[4783188]: Using pandoc: /opt/connect/ext/pandoc/2.11
2021-10-02T19:05:08.733739+00:00 shinyapps[4783188]: rmarkdown version: 2.9
2021-10-02T19:05:08.733790+00:00 shinyapps[4783188]: jsonlite version: 1.7.2
2021-10-02T19:05:08.934357+00:00 shinyapps[4783188]: Starting R with process ID: '26'
2021-10-02T19:05:08.733779+00:00 shinyapps[4783188]: knitr version: 1.33
2021-10-02T19:05:08.963216+00:00 shinyapps[4783188]: 
2021-10-02T19:05:08.733791+00:00 shinyapps[4783188]: RJSONIO version: (none)
2021-10-02T19:05:08.733797+00:00 shinyapps[4783188]: htmltools version: 0.5.1.1
2021-10-02T19:05:08.963841+00:00 shinyapps[4783188]:     box
2021-10-02T19:05:08.963217+00:00 shinyapps[4783188]: 
2021-10-02T19:05:08.963840+00:00 shinyapps[4783188]: The following object is masked from ‘package:graphics’:
2021-10-02T19:05:08.963840+00:00 shinyapps[4783188]: 
2021-10-02T19:05:08.963217+00:00 shinyapps[4783188]: Attaching package: ‘shinydashboard’
2021-10-02T19:05:08.963841+00:00 shinyapps[4783188]: 
2021-10-02T19:05:10.008023+00:00 shinyapps[4783188]: ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
2021-10-02T19:05:10.013142+00:00 shinyapps[4783188]: ✔ ggplot2 3.3.5     ✔ purrr   0.3.4
2021-10-02T19:05:10.013143+00:00 shinyapps[4783188]: ✔ tibble  3.1.3     ✔ dplyr   1.0.7
2021-10-02T19:05:10.013144+00:00 shinyapps[4783188]: ✔ tidyr   1.1.3     ✔ stringr 1.4.0
2021-10-02T19:05:10.194146+00:00 shinyapps[4783188]: ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
2021-10-02T19:05:10.194148+00:00 shinyapps[4783188]: ✖ dplyr::lag()    masks stats::lag()
2021-10-02T19:05:10.013144+00:00 shinyapps[4783188]: ✔ readr   2.0.0     ✔ forcats 0.5.1
2021-10-02T19:05:10.194148+00:00 shinyapps[4783188]: ✖ dplyr::filter() masks stats::filter()
2021-10-02T19:05:10.415161+00:00 shinyapps[4783188]: Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
2021-10-02T19:05:10.464817+00:00 shinyapps[4783188]: Listening on http://127.0.0.1:44842
2021-10-02T19:05:10.464815+00:00 shinyapps[4783188]: 
2021-10-02T19:05:16.625537+00:00 shinyapps[4783188]: Warning: Error in : Cannot open "D:/Sedimentary_Data_Analysis/www"; The file doesn't seem to exist.
2021-10-02T19:05:16.630916+00:00 shinyapps[4783188]:   113: <Anonymous>
2
  • Does your shiny App run inside a shiny R project template .Rproj? I have not problem with that, just writing: data.p <- st_read('deps.geojson') for instance, where deps.geojson is in the app dir, with app.R (or ui.R and server.R), not using system file.
    – Guillaume
    Oct 2, 2021 at 9:57
  • Yes, I am using the usual shiny template i.e. load the packages, define UI, define the server and run the app. I don't know about .Rproj. The app file itself is app.r.
    – Ed_Gravy
    Oct 2, 2021 at 10:20

1 Answer 1

0

Thanks to Guillaumme for his comment, so I was able to fix the problem by first moving the shiny app to a R project. Then in the app code write st_read as follows, and the app is able to pick up the shapefile when its published on shinyapps.io.

 sf_object = st_read(dsn = "www", layer = "Name") 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.