Render
The WebIO.render
function is the primary method of extending WebIO and providing interoperability between WebIO and other libraries. For example, one could define a custom method to render a MyPlot
type. See the Extending WebIO documentation for more information.
Internal API
WebIO.@register_renderable
— Macro@register_renderable(MyType)
@register_renderable(MyType) do
# Render definition
end
Register a type as renderable by WebIO. This enables your type to be displayed in the appropriate WebIO frontends (e.g. Jupyter) without any additional work.
This macro may be called either with just the type that you wish to mark as renderable or with the body of the WebIO.render
method using do-block syntax.
The do-block syntax requires parentheses around the typename. Additionally, due to inconsistencies in the way macros are resolved, the do-block syntax must be invoked using @WebIO.register_renderable
(not WebIO.@register_renderable
). If the @WebIO.register_renderable
syntax looks ugly, it might be preferable to directly import the macro and use it without qualifying its name.
This macro also defines a method for Base.show
with the text/html
MIME so you should not need to define your own.
Examples
struct ScatterPlot
x::Vector{Float64}
y::Vector{Float64}
end
# Do-block syntax
# Note that the `@` comes before `WebIO`
@WebIO.register_renderable(ScatterPlot) do plot
# Construct the scatter plot using DOM primitives...
return node(...)
end
# Do-block syntax with explicit import
using WebIO: @register_renderable
@register_renderable(ScatterPlot) do plot ... end
# Type name syntax
WebIO.render(plot::ScatterPlot) = node(...)
@WebIO.register_renderable ScatterPlot
WebIO.register_renderable
— Functionregister_renderable(MyType)
This function is deprecated. Please use WebIO.@register_renderable
instead.
This function was deprecated because it contained too much magic (since magic is firmly within the domain of macros). In particular, this function resorts to eval
-ing new method definitions for the types passed into it which is not what a normal function is supposed to do.
WebIO.render
— Functionrender(x::MyType)
Generic function that defines how a Julia object is rendered. Should return a Node
object.
Examples
struct MyPlot
s::Scope
end
WebIO.render(p::MyPlot) = WebIO.render(p.s)
Private API
WebIO.observable_to_scope
— FunctionWrap an observable in a scope to enable "live updating."
This method also contains distinct code paths for the cases where the observable contains "non-simple" data types (in particular, observables that contain Nodes, Scopes, or Widgets need specially handling).