Hello,
I'm trying to print data frame using javascript. In order to do that I'm trying to make double loop - combaining js loop and r loop. Since giving to JS RStudio variable is pretty easy and I don't know how to give to R javascript variable I came up with solution like this:
---
output: html_document
---
```{r echo = FALSE}
knitr::opts_chunk$set(echo = FALSE)```
```{r}
Week <- strftime(Sys.Date(), format = "%V")
x <- 1:52
df <- as.data.frame(matrix(x, nrow = 1, ncol = 52))```
<html>
<head>
<meta charset = "UTF-8">
<!-- Java Script -->
<script>
function Start()
{
function Create_Row()
{
```{r}
x <- 1:52 ```
var table = '';
var i;
table += '<tr>';
for (i = 1; i < `r Week`; i++)
{
```{r}
j <- x[1]
```
table += '<td> `r df[1, j]` </td>';
```{r}
x <- x[-1]
```
}
table += '</tr>';
return table;
}
table = Create_Row();
document.getElementById("FirstRow").insertRow().innerHTML += table;
}
</script>
</head>
<body onload = "Start();">
<table border = 1>
<tbody id = "FirstRow"></tbody>
</table>
</body>
</html>
Unfortunately it looks like R chunks runs only ones in javascript loop:
for (i = 1; i < `r Week`; i++)
{
```{r}
j <- x[1]
```
table += '<td> `r df[1, j]` </td>';
```{r}
x <- x[-1]
```
}
instead of running with every loop step (Could be seen by changing j <- x[1] to j <- x[2] and comparing results).
I will be grateful for your help in solving my problem.