Variables can be interchanged between R and OJS.
1 R to OJS
In this example, a data set in R is sent over to OJS to be plotted.
```{webr}
#| define:
#| - irism
irism <- iris
colnames(irism) <- gsub("[.]","_",tolower(colnames(irism)))
```Code
viewof x = Inputs.select(Object.keys(irism[0]), {value: "petal_width", multiple: false, label: "X axis"})
viewof y = Inputs.select(Object.keys(irism[0]), {value: "sepal_width", multiple: false, label: "Y axis"})Code
Plot.plot({
marks: [
Plot.dot(irism, {
x: x,
y: y,
fill: "species",
title: (d) =>
`${d.species} \n Petal length: ${d.petal_length} \n Sepal length: ${d.sepal_length}`
})
],
grid: true
})2 OJS to R
In this example, a dataset in R is filtered in R based on input from OJS.
Code
viewof sp = Inputs.radio(["setosa", "versicolor", "virginica"], {label: "Select species:", value: "setosa"})```{webr}
#| input:
#| - sp
iris[iris$Species %in% sp,]
```