【发布时间】:2021-10-26 21:51:00
【问题描述】:
根据https://github.com/jpowell96/readFilesWithFetch/blob/master/index.html 的想法,我正在尝试从“www”文件夹中的 .csv 文件中读取数据,但我只得到“正在读取文件”行并且未显示数据。我也尝试在 fetch (fetch(file:///C:/.../www/this_data.csv')) 中使用完整路径,但得到了相同的结果。
任何想法让它工作? (目前在 Windows 中工作,但最终会将其移植到 shinyapps.io。)
非常感谢
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
tags$div(
tags$html("Reading file"),
tags$script("
fetch('./www/this_data.csv')
.then(response => response.text())
.then(csvString => {
// Split the csv into rows
const rows = csvString.split('\n');
for (row of rows) {
// Split the row into each of the comma separated values
console.log(row.split(','));
}
});
")
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
这是 this_data.csv:
Date,Open,High,Low,Close
1/2/2007,50.03978,50.11778,49.95041,50.11778
1/3/2007,50.2305,50.42188,50.2305,50.39767
1/4/2007,50.42096,50.42096,50.26414,50.33236
1/5/2007,50.37347,50.37347,50.22103,50.33459
1/6/2007,50.24433,50.24433,50.11121,50.18112
1/9/2007,49.99489,49.99489,49.80454,49.91333
1/10/2007,49.91228,50.13053,49.91228,49.97246
1/11/2007,49.88529,50.2391,49.88529,50.2391
【问题讨论】:
-
为什么你试图在客户端 javascript 中获取数据而不是在你的服务器函数中读取和解析它?你到底希望完成什么?
标签: javascript r shiny shinyapps shinyjs