Overview
Patchwork includes nine built-in plugins for common dashboard components. Each plugin is designed to work seamlessly with the dashboard system and requires no additional configuration. The built-in plugins are:
- HTML - Raw HTML content
- Markdown - Markdown rendering
- ChartJs - Chart.js charts
- Highcharts - Highcharts charts
- Plotly - Plotly charts and maps
- Leaflet - Leaflet maps
- Mermaid - Mermaid diagrams
- DataTables - Interactive tables
- ELKJs - Graph layouts
Creating Custom Plugins
Extend Patchwork with any JavaScript library by creating custom plugins.
Plugin Interface
All plugins must implement to_html. Optional functions include css_deps, js_deps, init_script, and css.
module MyPluginModule
import ..Plugin, ..to_html, ..css_deps, ..js_deps, ..init_script, ..css
export MyPlugin
struct MyPlugin <: Plugin
    content::String
end
# Required
to_html(plugin::MyPlugin) = "<div class='myplugin'>$(plugin.content)</div>"
# Optional
css_deps(::Type{MyPlugin}) = ["https://cdn.example.com/lib.css"]
js_deps(::Type{MyPlugin}) = ["https://cdn.example.com/lib.js"]
init_script(::Type{MyPlugin}) = "// initialization code"
css(::Type{MyPlugin}) = ".myplugin { padding: 1rem; }"
endBest Practices
- Use unique CSS classes to avoid conflicts
- Generate unique IDs with UUIDs for elements
- Store data in attributes using data-*attributes
- Query by class in init_script to initialize all instances
- Handle visibility for libraries that need visible elements
- Use different module/struct names to avoid conflicts
- Add error handling in JavaScript initialization
API Reference
Patchwork.Plugin — TypePluginAbstract base type for all Patchwork plugins.
All plugin types must subtype Plugin and implement the to_html function. Optionally, plugins can implement css_deps, js_deps, init_script, and css functions to provide external dependencies and initialization code.
Example
struct MyPlugin <: Plugin
    content::String
end
to_html(plugin::MyPlugin) = "<div>$(plugin.content)</div>"See also: to_html, css_deps, js_deps, init_script, css
Patchwork.css — Methodcss(::Type{<:Plugin}) -> StringReturn custom CSS styles for a plugin type.
Arguments
- ::Type{<:Plugin}: Plugin type (not instance)
Returns
- String: CSS styles
Default
Returns "" if not implemented.
Example
css(::Type{MyPlugin}) = """
    .my-plugin {
        padding: 1rem;
        border: 1px solid #ccc;
    }
"""Patchwork.css_deps — Methodcss_deps(::Type{<:Plugin}) -> Vector{String}Return vector of CSS dependency URLs for a plugin type.
Arguments
- ::Type{<:Plugin}: Plugin type (not instance)
Returns
- Vector{String}: CDN URLs for CSS dependencies
Default
Returns String[] if not implemented.
Example
css_deps(::Type{MyPlugin}) = ["https://cdn.example.com/style.css"]Patchwork.init_script — Methodinit_script(::Type{<:Plugin}) -> StringReturn JavaScript initialization code for a plugin type.
This code runs after all dependencies are loaded and the DOM is ready. Typically used to initialize JavaScript libraries on plugin elements.
Arguments
- ::Type{<:Plugin}: Plugin type (not instance)
Returns
- String: JavaScript initialization code
Default
Returns "" if not implemented.
Example
init_script(::Type{MyPlugin}) = """
    document.querySelectorAll('.my-plugin').forEach(el => {
        // Initialize library
    });
"""Patchwork.js_deps — Methodjs_deps(::Type{<:Plugin}) -> Vector{String}Return vector of JavaScript dependency URLs for a plugin type.
Arguments
- ::Type{<:Plugin}: Plugin type (not instance)
Returns
- Vector{String}: CDN URLs for JavaScript dependencies
Default
Returns String[] if not implemented.
Example
js_deps(::Type{MyPlugin}) = ["https://cdn.example.com/lib.js"]See also: css_deps, init_script
Patchwork.to_html — Functionto_html(plugin::Plugin) -> StringConvert plugin to HTML string. Must be implemented for all custom plugins.
Arguments
- plugin::Plugin: Plugin instance to convert
Returns
- String: HTML representation of the plugin
Example
to_html(plugin::MyPlugin) = "<div class='my-plugin'>$(plugin.content)</div>"Patchwork.get_plugin_type — Methodget_plugin_type(plugin::Plugin) -> StringGet the lowercase type name of a plugin.
This function extracts the plugin type name from the fully qualified type name and converts it to lowercase. Used internally for HTML class generation and plugin identification.
Arguments
- plugin::Plugin: Plugin instance
Returns
- String: Lowercase plugin type name
Example
plugin = Patchwork.ChartJs("Title", "bar", Dict{String,Any}(...))
get_plugin_type(plugin)  # Returns "chartjs"