I am writing my first htmlwidget. I can load the text file placed in my library folder using the below code.
HTMLWidgets.widget({
name: 'myApp',
type: 'output',
factory: function(el, width, height) {
// TODO: define shared variables for this instance
return {
renderValue: function(x) {
//Load data file in Library
fetch('lib/myApp/./lib/myApp/data.txt')
.then(response => response.text())
.then(text => console.log(text));
},
resize: function(width, height) {
// TODO: code to re-render the widget with a new size
}
};
}
});
When I replace the link to a local file for instance: "C:/Users/me/folder/data.txt" it will not load the text file even though I have no problems loading it into Rstudio using:
fileload <- read.csv("C:/Users/me/folder/data.txt")
How can I load local files into the htmlwidget? And how can I do this for instance with a file uploaded to a shiny app?
The idea is that somebody downloads my library and is than able to load a local file or a file uploaded from a Shiny app into the widget. Unfortunatly, I cannot load the data into R and send it as a parameter because it is in a specific file format. Loading it into R changes the formatting making it unreadable.