Viewer Tests

Tests of all the different mime types we support. One test per language, if language supports the mime.

test2.csv

CSV

issue #4535

cp(
test2.csv
, "/results/test.csv");
0.4s
0 items
using CSV
foo = CSV.read(
test2.csv
)
14.6s
ABC, DEF,,G
1234,356
65,432,1
2 items
using DataFrames
DataFrame(x = rand(10), asjdkasdj = rand(10))
0.9s
xasjdkasdj
0.50901365553036610.8581307495621857
0.54936307347869320.5243223862081208
0.198264153110257360.7369649352443028
0.79612183693332760.00839228128899161
0.041857528964618140.11437833360214111
0.63947679175441170.5950335462116101
0.34125318332813450.8104054910573486
0.67261727348608980.3750576176542233
0.61130105932909710.6031731297612366
0.08708443314318770.7003199617863123
10 items
import pandas as pd
import numpy as np
x = pd.DataFrame({"x": np.random.rand(10), "asjdkasdj": np.random.rand(10)})
x
0.8s
Python
xasjdkasdj
00.51980533796151820.8145266334454069
10.40109591614172180.5026947276751768
20.34628799332815450.22826987334201154
30.489810688242642840.3300664188943968
40.00167399577299587320.816789730229122
50.55186532430850810.598266509057624
60.93035999062711440.7946055995174718
70.479906317124831670.9471247490222806
80.207822542995225850.03409555654878671
90.65790676350992780.14749341535234872
10 items
x = runif(10)
asjdkasdj = runif(10)
data.frame(x, asjdkasdj)
__out-0.csv
echo "\"x\",\"asjdkasdj\"
0.886204954236746,0.994749354198575
0.939964033663273,0.348342207027599
0.841421562014148,0.251535881310701
0.191597430035472,0.169539803639054
0.552916625980288,0.957168905297294
0.649154531303793,0.336226592073217
0.834337387699634,0.292891587363556
0.940559577196836,0.0146519427653402
0.062867890112102,0.192729525500908
0.500695133814588,0.318394189001992
" > /results/test.csv
0.4s
Bash in Clojure
0 items

HTML

HTML("<h3>hi</h3>")
0.6s

hi

class HTML(object):
  def _repr_html_(self):
    return '<h3>hi</h3>'
    
HTML()
0.2s
Python

hi

{:nextjournal/viewer "html" :nextjournal.viewer/value "<h3>hi</h3>"}
0.1s
Clojure

hi

echo '<h3>hi</h3>' > /results/test.html
0.4s
Bash in Clojure

IFrame

using WebSockets, WebIO, Interact
s = @manipulate for i in 1:10
	"hello number: $i"
end
WebIO.node(:div, s, style = Dict(:height => 80))
0.9s
WebIOJulia
library(leaflet)
options(nextjournal.display.htmlwidgetsEnabled=TRUE)
leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")

PNG

struct PNG end
function Base.show(io::IO, ::MIME"image/png", ::PNG)
  write(io, read(
test.png
))
end
PNG()
1.6s
class PNG(object):
  def _repr_png_(self):
    f = open(
test.png
, "rb")
    bin = f.read()
    f.close()
    return bin
    
PNG()
0.2s
Python
cp NJ__REF_ /results/test.png
0.2s
Bash in Python

JPEG

struct JPEG end
function Base.show(io::IO, ::MIME"image/jpeg", ::JPEG)
  write(io, read(
test_image.jpg
))
end
JPEG()
0.8s
class JPEG(object):
  def _repr_jpeg_(self):
    f = open(
test_image.jpg
, "rb")
    bin = f.read()
    f.close()
    return bin
    
JPEG()
0.2s
Python
cp NJ__REF_ /results/test.jpg
0.2s
Bash in Python

SVG

test.svg
struct SVG end
function Base.show(io::IO, ::MIME"image/svg+xml", ::SVG)
  write(io, read(
test.svg
))
end
SVG()
2.4s
class SVG(object):
  def _repr_svg_(self):
    f = open(
test.svg
, "r")
    bin = f.read()
    f.close()
    return bin
    
SVG()
0.2s
Python
cp NJ__REF_ /results/test.svg
0.2s
Bash in Python

Plotly

using PlotlyBase
PlotlyBase.Plot(1:10, (1:10) .^ 2)
4.6s
import plotly.graph_objs as go
import numpy as np
x = np.arange(10)
fig = go.Figure(data=[go.Scatter(x=x, y=x**2)])
fig
1.2s
Python
^{:nextjournal/viewer :plotly}
{:data [{
	:x [1 2 3 4 5 6 7 8 9 10] 
  :y [1 4 9 16 25 36 49 64 81 100]
}]}
0.1s
Clojure

Vegalite

^{:nextjournal/viewer "vega-lite"}
{:width 650
 :height 400
 :data
 {:url "https://vega.github.io/vega-datasets/data/us-10m.json"
  :format
  {:type "topojson" :feature "counties"}}
 :transform
 [{:lookup "id"
   :from
   {:data {:url "https://vega.github.io/vega-datasets/data/unemployment.tsv"}
    :key "id"
    :fields ["rate"]}}]
 :projection {:type "albersUsa"}
 :mark "geoshape"
 :encoding
 {:color {:field "rate" :type "quantitative"}}}
0.2s
Clojure
echo '{
  "width": 500, "height": 300,
  "data": {"url": "https://vega.github.io/vega-datasets/data/unemployment-across-industries.json"},
  "mark": "area",
  "encoding": {
    "x": {
      "timeUnit": "yearmonth", "field": "date", "type": "temporal",
      "axis": {"domain": false, "format": "%Y", "tickSize": 0}
    },
    "y": {
      "aggregate": "sum", "field": "count","type": "quantitative",
      "axis": null,
      "stack": "center"
    },
    "color": {
    	"field":"series",
      "type":"nominal",
      "scale":{"scheme": "category20b"}
    }
  }
}' > /results/plot.vl.json
0.3s
Bash in Clojure
Loading viewer…
pip install altair
5.1s
Bash in Python
import altair as alt
source = "https://vega.github.io/vega-datasets/data/unemployment-across-industries.json"
alt.Chart(source).mark_area().encode(
    alt.X('yearmonth(date):T',
        axis=alt.Axis(format='%Y', domain=False, tickSize=0)
    ),
    alt.Y('sum(count):Q', stack='center', axis=None),
    alt.Color('series:N',
        scale=alt.Scale(scheme='category20b')
    )
).interactive()
1.2s
Python

Latex

struct Latex end
function Base.show(io::IO, ::MIME"text/latex", ::Latex)
  print(io, "\\int_0^\\infty e^{-x^2} dx=\\frac{\\sqrt{\\pi}}{2}")
end
Latex()
0.5s
0ex2dx=π2\int_0^\infty e^{-x^2} dx=\frac{\sqrt{\pi}}{2}
class Latex(object):
  def _repr_latex_(self):
    return "\\int_0^\\infty e^{-x^2} dx=\\frac{\\sqrt{\\pi}}{2}"
    
Latex()
0.3s
Python
0ex2dx=π2\int_0^\infty e^{-x^2} dx=\frac{\sqrt{\pi}}{2}
echo "\\int_0^\\infty e^{-x^2} dx=\\frac{\\sqrt{\\pi}}{2}" > "/results/test.latex"
0.1s
Bash in Python
{:nextjournal/viewer "formula" :nextjournal.viewer/value "\\int_0^\\infty e^{-x^2} dx=\\frac{\\sqrt{\\pi}}{2}"}
0.1s
Clojure
0ex2dx=π2\int_0^\infty e^{-x^2} dx=\frac{\sqrt{\pi}}{2}

Plain

1:10
0.5s
1:10
()-> "this is a function"
0.7s
#5 (generic function with 1 method)
class Plain:
  def test():
    return ""
Plain()
0.2s
Python
<Plain object...x7ff417accf60>
def func(msg):
  print(msg)
func
0.2s
Python
<function fun...x7ff4202aaae8>
{:nextjournal/viewer "text" :nextjournal.viewer/value "hi"}
0.0s
Clojure
hi
echo "hi" > /results/test.txt
0.2s
Bash in Clojure
empty
list(1, 2, 3)
f <- function(x){x + 1}
f

JSON

struct APP_JSON end
function Base.show(io::IO, ::MIME"application/json", ::APP_JSON)
  JSON.print(io, Dict(:data => [2,3,4]))
end
APP_JSON()
0.7s
Object {data: Array(3)}
class JSON(object):
  def _repr_json_(self):
    return "{\"data\":[2,3,4]}"
    
JSON()
0.2s
Python
Object {data: Array(3)}
echo "{\"data\":[2,3,4]}" > /results/test.json
0.2s
Bash in Clojure
nil
{:data [2 3 4]}
0.0s
Clojure
Map {:data: Vector(3)}
Runtimes (4)