Build an iframe snippet for vizRd
build_iframe_snippet.RdConstruct a copy/paste-ready iframe snippet from a vizRd share URL. The
snippet forces embed=1 and includes a small host-side vizrd:resize
listener for the package-local child resize bridge.
Usage
build_iframe_snippet(
src,
title = "vizRd visualization",
id = "vizrd-frame",
class = NULL,
width = "100%",
height = 640,
loading = c("lazy", "eager"),
allowfullscreen = FALSE,
resize = TRUE
)Arguments
- src
Share URL or app URL to embed. HTTP(S) URLs and app-relative paths are supported; local filesystem paths and unsafe schemes are rejected.
- title
Accessible iframe title.
- id
Iframe id. Unsafe characters are replaced with
-.- class
Optional iframe class attribute.
- width
CSS width for the iframe.
- height
Minimum iframe height in pixels.
- loading
Iframe loading behavior, either
"lazy"or"eager".- allowfullscreen
Whether to include the
allowfullscreenattribute.- resize
Whether to include the host-side
vizrd:resizelistener.
Examples
build_iframe_snippet(
src = build_share_url(
base_url = "https://example.org/vizrd/",
dataset = "sales",
chart = "histogram",
numeric = "revenue"
)
)
#> [1] "<iframe id=\"vizrd-frame\" src=\"https://example.org/vizrd/?dataset=sales&chart=histogram&numeric=revenue&embed=1\" title=\"vizRd visualization\" loading=\"lazy\" style=\"width: 100%; min-height: 640px; border: 0;\"></iframe>\n<script>\n(function() {\n var frame = document.currentScript.previousElementSibling;\n window.addEventListener(\"message\", function(event) {\n if (!frame || event.source !== frame.contentWindow) return;\n var data = event.data || {};\n if (data.type === \"vizrd:resize\" && Number.isFinite(data.height)) {\n frame.style.height = Math.max(320, Math.ceil(data.height)) + \"px\";\n }\n });\n})();\n</script>"