is there a way to pass an element_id to the rs_viewer call when invoking the default internal viewer in RStudio?
getOption('viewer')
function (url, height = NULL)
{
if (!is.character(url) || (length(url) != 1))
stop("url must be a single element character vector.",
call. = FALSE)
if (identical(height, "maximize"))
height <- -1
if (!is.null(height) && (!is.numeric(height) || (length(height) !=
1)))
stop("height must be a single element numeric vector or 'maximize'.",
call. = FALSE)
invisible(.Call("rs_viewer", url, height))
}
this would allow for multiple outputs in the viewer pane, like with htmlwidgets.
for example when a ggplotly
is created it is given a new elementId, thus gives a new element in the viewer for each plot created.
plotly:::as_widget
function (x, ...)
{
if (inherits(x, "htmlwidget"))
return(x)
attr(x, "TOJSON_FUNC") <- to_JSON
w <- htmlwidgets::createWidget(name = "plotly", x = x, width = x$layout$width,
height = x$layout$height, sizingPolicy = htmlwidgets::sizingPolicy(browser.fill = TRUE,
defaultWidth = "100%", defaultHeight = 400), preRenderHook = plotly_build,
dependencies = c(list(typedArrayPolyfill()), crosstalk::crosstalkLibs(),
list(plotlyMainBundle())))
w$elementId <- w$elementId %||% new_id()
w
}