Кажется, у вас отсутствует куча вложенных вызовов list
:)
Прежде всего обратите внимание, что
> identical(rep(list(), 100), list())
[1] TRUE
Вам нужно сделать
> rep(list(list()), length(ids))
[[1]]
list()
[[2]]
list()
.
Теперь для назначения:
> DT = data.table(id = ids, x = rep(list(list()), length(ids)))
> DT
id x
1: 1 <list>
2: 2 <list>
> DT[1, x:=list(list(c(2, 3)))] # notice the additional `list()`
> DT
id x
1: 1 2,3
2: 2 <list>
Вы можете использовать Express, чтобы делать разные вещи для GET и POST.
Использовать POST для запросов веб-сервера, поскольку браузеры используют GET.
var express = require('express');
var app = express();
var data = '{"example":{"online":true,"status":"200"}}';
app.get('/', function(req, res) {
res.send('<html><head><script>window.location.href = \'https://google.com/\'</script></head><body>You shouldn\'t be here! <a href=\'https://google.com\'>Exit</a></body></html>');
/** Redirect the browser to google with window.location.href
* Change this to your site */
});
app.post('/', function(req, res) {
/** You could add some auth code here but
* if your sending it all to the client there isn't much of a difference
* because people could read it from the website. */
res.type('json');
res.json(data);
/* Webserver --> Bot */
res.end();
});
app.listen(8080);
console.log('API Online');
Вам нужно будет использовать setInterval(() => {}, 15000);
для обновления переменной данных, и вам нужно будет проанализировать данные на клиенте.
XMLHttpRequest должен работать достаточно хорошо для этого