shiny::markRenderFunction 是如何使用的?
How is shiny::markRenderFunction used?
问题 How can I change the size of rgl plots in Shiny RMarkdown? 讨论了在动态 R Markdown 文档中很难设置 rglwidget
的大小这一事实。问题是 Shiny 输出函数设置了大小,但没有明显的方法可以将任何参数传递给它,因此始终使用默认的 512 x 512 大小。
rgl::renderRglwidget
函数是根据htmlwidgets::shinyRenderWidget
中的例子写的,它没有提供传递输出参数的方法:
rglwidgetOutput <- function(outputId, width = '512px', height = '512px'){
shinyWidgetOutput(outputId, 'rglWebGL', width, height, package = 'rgl')
}
renderRglwidget <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
shinyRenderWidget(expr, rglwidgetOutput, env, quoted = TRUE)
}
shiny
文档显示它应该使用 shiny::markRenderFunction
以允许传入 outputArgs
,但我找不到示例。
renderRglwidget
应该是什么样子才能使用 shiny::markRenderFunction
?
虽然可能有一些注意事项,但事实证明这相当简单。
rglwidgetOutput
功能原样很好,但 renderRglwidget
需要修改为
renderRglwidget <- function(expr, env = parent.frame(), quoted = FALSE,
outputArgs = list()) {
if (!quoted) { expr <- substitute(expr) } # force quoted
markRenderFunction(rglwidgetOutput,
shinyRenderWidget(expr, rglwidgetOutput, env, quoted = TRUE),
outputArgs = outputArgs)
}
已对链接问题 How can I change the size of rgl plots in Shiny RMarkdown? 进行编辑以说明其用法。
注意事项:设置 outputArgs = list(height = "auto")
似乎选择零高度而不是剩余的 window 高度。 width = "auto"
在 window 调整大小后 确实有效;前
调整大小,它看起来太大了。同样,使用百分比值
width
或 height
不尽如人意。指定整数值
或带有 px
单位的字符串(例如 width = "300px"
)看起来不错。
问题 How can I change the size of rgl plots in Shiny RMarkdown? 讨论了在动态 R Markdown 文档中很难设置 rglwidget
的大小这一事实。问题是 Shiny 输出函数设置了大小,但没有明显的方法可以将任何参数传递给它,因此始终使用默认的 512 x 512 大小。
rgl::renderRglwidget
函数是根据htmlwidgets::shinyRenderWidget
中的例子写的,它没有提供传递输出参数的方法:
rglwidgetOutput <- function(outputId, width = '512px', height = '512px'){
shinyWidgetOutput(outputId, 'rglWebGL', width, height, package = 'rgl')
}
renderRglwidget <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
shinyRenderWidget(expr, rglwidgetOutput, env, quoted = TRUE)
}
shiny
文档显示它应该使用 shiny::markRenderFunction
以允许传入 outputArgs
,但我找不到示例。
renderRglwidget
应该是什么样子才能使用 shiny::markRenderFunction
?
虽然可能有一些注意事项,但事实证明这相当简单。
rglwidgetOutput
功能原样很好,但 renderRglwidget
需要修改为
renderRglwidget <- function(expr, env = parent.frame(), quoted = FALSE,
outputArgs = list()) {
if (!quoted) { expr <- substitute(expr) } # force quoted
markRenderFunction(rglwidgetOutput,
shinyRenderWidget(expr, rglwidgetOutput, env, quoted = TRUE),
outputArgs = outputArgs)
}
已对链接问题 How can I change the size of rgl plots in Shiny RMarkdown? 进行编辑以说明其用法。
注意事项:设置 outputArgs = list(height = "auto")
似乎选择零高度而不是剩余的 window 高度。 width = "auto"
在 window 调整大小后 确实有效;前
调整大小,它看起来太大了。同样,使用百分比值
width
或 height
不尽如人意。指定整数值
或带有 px
单位的字符串(例如 width = "300px"
)看起来不错。