No Jupyter, but a self-hosted server with standard Docker images that run the code snippets:
The server runs at:
Languages (so far):
msg = "Hello, World!"
print(msg)
``` {macro="live-code" language="python"}
msg = "Hello, World!"
print(msg)
```
fn main() {
print!("Hello, World!");
}
``` {macro="live-code" language="rust"}
fn main() {
print!("Hello, World!");
}
```
main = putStrLn "Hello, World!"
``` {macro="live-code" language="haskell"}
main = putStrLn "Hello, World!"
```
language="haskell" expects a complete Haskell program with a proper main function.
let a = 1
let b = 2
a + b
``` {macro="live-code" language="haskell" sandbox="ghci"}
let a = 1
let b = 2
a + b
```
language="haskell" sandbox="ghci" expects a Haskell snippet which is fed to GHCi instead of a complete Haskell program.
record FortyTwo(int value) {}
var ft = new FortyTwo(42);
System.out.println(ft);
``` {macro="live-code" language="java"}
record FortyTwo(int value) {}
var ft = new FortyTwo(42);
System.out.println(ft);
```
language="java" expects a Java snippet which is fed to jshell. Also, jshell needs a lot of memory and is dog slow.
console.log("42")
``` {macro="live-code" language="javascript" engine="browser"}
console.log("42")
```
language="javascript" engine="browser" executes the code directly in the browser.
A simple template is used around the code.
import Data.Text
mario = "MARIO"
main = do
print "the template added this"
##CODE##
print "the template added this"
``` {macro="live-code" language="haskell" template="../static/live-code-template.hs.txt"}
print (mario <> mario <> mario)
The next cell depends on this code
a = 1
b = 2
a + b
This depends on the previous cell
c = 3
a + b + c
# Two Dependent Haskell Cells {.columns}
## {.left}
The next cell depends on this code
``` {#lcm-cell-1 macro="live-code" language="haskell" sandbox="ghci"}
a = 1
b = 2
a + b
```
## {.right}
This depends on the previous cell
``` {#lcm-cell-2 macro="live-code" language="haskell" sandbox="ghci" depends-on="lcm-cell-1"}
c = 3
a + b + c
```
print("Hello, World 0!")
print("Hello, World 1!")
# Two Dependent Python Cells {.columns}
## Independent cell {.left}
``` {#py-cell-1 macro="live-code" language="python"}
print("Hello, World 0!")
```
## Depends on left cell{.right}
``` {macro="live-code" language="python" depends-on="py-cell-1"}
print("Hello, World 1!")
```
import io
import numpy as np
import matplotlib.pyplot as plt
data = {"a": np.arange(50), "c": np.random.randint(0, 50, 50), "d": np.random.randn(50)}
data["b"] = data["a"] + 10 * np.random.randn(50)
data["d"] = np.abs(data["d"]) * 100
plt.scatter("a", "b", c="c", s="d", data=data)
plt.xlabel("entry a")
plt.ylabel("entry b")
plt.show()
stream = io.StringIO()
plt.savefig(stream, format="svg")
print(stream.getvalue())
``` {macro="live-code" language="python" output-mode="svg"}
import io
import numpy as np
import matplotlib.pyplot as plt
data = {"a": np.arange(50), "c": np.random.randint(0, 50, 50), "d": np.random.randn(50)}
data["b"] = data["a"] + 10 * np.random.randn(50)
data["d"] = np.abs(data["d"]) * 100
plt.scatter("a", "b", c="c", s="d", data=data)
plt.xlabel("entry a")
plt.ylabel("entry b")
plt.show()
stream = io.StringIO()
plt.savefig(stream, format="svg")
print(stream.getvalue())
```