rstudio中rs_viewer的element_id

时间:2018-06-01 12:56:53

标签: r rstudio

有没有办法在调用RStudio中的默认内部查看器时将element_id传递给rs_viewer调用?

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))
}

这将允许查看器窗格中的多个输出,例如htmlwidgets。

例如,当创建ggplotly时,会给它一个新的elementId,从而在查看器中为每个创建的绘图提供一个新元素。

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
}

0 个答案:

没有答案