What I want is to generate a html document with quarto
and execute a code chunk every 10 seconds. Is it possible? (In shiny I can get similar functionality by using reactivePoll
package).
This is my attempt:
---
title: "Auotmatic refreshing"
format: html
editor_options:
chunk_output_type: console
---
```{r}
# This is the chunk to re-execute
cat(Sys.time())
```
<script>
// Function to reload the chunk every 10 seconds
function refreshChunk() {
document.querySelectorAll('.cell .output').forEach(el => el.remove());
let rChunks = document.querySelectorAll('.cell_code.cell_r');
rChunks.forEach(chunk => {
let button = chunk.querySelector('button[aria-label="Run Cell"]');
if (button) {
button.click();
}
});
}
setInterval(refreshChunk, 10000);
</script>
1