Following an idea from from https://github.com/jpowell96/readFilesWithFetch/blob/master/index.html, I'm trying to read data from a .csv file from the 'www' folder but I get only the 'Reading file' line and the data is not shown. I tried with full path too in fetch (fetch(file:///C:/.../www/this_data.csv')) but got the same results.
Any idea to make it work? (Currently working in Windows but eventually will port it to shinyapps.io.)
Many thanks
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 is 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