【问题标题】:R Shiny not reading file pathR Shiny不读取文件路径
【发布时间】:2020-11-14 13:06:29
【问题描述】:

考虑一个具有以下文件夹结构的闪亮应用 (github here):

├── data
│   └── import_finance.R
│   └── data.xlsx
├── dashboard.R
├── ui_elements
│   └── sidebar.R
│   └── body.R

import_finance.R 在闪亮的应用程序中未运行时可以正常运行。但是,当运行闪亮的应用程序时,它无法识别路径。

# list of quarterly earnings worksheets
file_paths <- list.files('dashboard/data', pattern = 'xlsx', full.names = TRUE)
path <- file_paths[1]


# import all sheets from each workbook and merge to one df

 import <-
  path %>%
  excel_sheets() %>%
  set_names() %>%
  map_df(xlsx_cells, path = path) %>%
  mutate(workbook = word(path, -1, sep = '/')) # add column with file_name

闪亮说Error: path does not exist: ‘NA’。请注意import_finance.R 是通过source("data/import_finance.R")dashboard.R 中调用的。

即使指定完整路径,错误仍然存​​在。这个thread 声称同样的错误:

> system.file("/Users/pblack/Documents/Git Projects/opensource-freetoplay-economics/dashboard/data/dashboard/data/ATVI 12-Quarter Financial Model Q1 CY20a.xlsx")  
[1] ""

知道我犯的错误吗?奇怪的是脚本运行良好,但作为闪亮的应用程序运行时却不行。

【问题讨论】:

  • 试试source("./data/import_finance.R")
  • 不幸的是同样的错误

标签: r shiny readxl


【解决方案1】:

这里的错误在

# list of quarterly earnings worksheets
file_paths <- list.files('dashboard/data', pattern = 'xlsx', full.names = TRUE)

当闪亮的应用程序运行时,它从data 文件夹作为工作目录运行运行source("data/import_finance.R")

为了方便

# list of quarterly earnings worksheets
file_paths <- list.files('data', pattern = 'xlsx', full.names = TRUE)

【讨论】:

    猜你喜欢
    • 2014-09-15
    • 2016-06-25
    • 1970-01-01
    • 2018-12-21
    • 2013-02-12
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多