【问题标题】:st_read path for shinyapp in RR中shinyapp的st_read路径
【发布时间】:2021-10-02 09:29:53
【问题描述】:

通常当使用st_read 时,您将路径放入dsn,但如果您在dsn 中放入完整路径,则会出现错误,因为该文件路径在服务器上不存在。所以,现在我把 shapefile 放到了 www 文件夹中,但是我不知道应该把 dsn 放到什么路径中,这样应用才能获取 shapefile。

我该如何解决这个问题?

应用中的当前功能代码:

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

日志中的以下错误会破坏应用程序

    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>

【问题讨论】:

  • 您的闪亮应用程序是否在闪亮的 R 项目模板 .Rproj 中运行?我对此没有问题,只是写:data.p &lt;- st_read('deps.geojson') 例如,deps.geojson 在应用程序目录中,带有 app.R(或 ui.R 和 server.R),不使用系统文件。
  • 是的,我使用的是通常的闪亮模板,即加载包、定义 UI、定义服务器并运行应用程序。我不知道.Rproj。应用文件本身是 app.r.

标签: r shiny sf


【解决方案1】:

感谢 Guillaumme 的评论,因此我能够通过首先将 shiny 应用程序移动到 R 项目来解决问题。然后在app代码中写st_read如下,当shapefile发布到shinyapps.io时,应用程序就可以获取它了。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 2019-03-27
    • 2019-03-24
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    相关资源
    最近更新 更多