我正在使用RMarkdown创建一个Shiny文档,并且包含来自rgl
的反应图。但是,我无法更改渲染图的视口大小。也就是说,我无法更改绘制图形的空间的高度和宽度。如何使渲染图大于默认值?
编辑:在knitr选项中交替fig.width
并不会改变Shiny渲染函数的宽度。
以下是我到目前为止的文件。
---
title: "Untitled"
runtime: shiny
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rgl)
library(dplyr)
source("https://raw.githubusercontent.com/trestletech/rgl/master/vignettes/setup.R")
```
```{r, rgl = TRUE, echo = FALSE}
inputPanel(
sliderInput("b1", label = withMathJax("\\(\\beta_1\\)"), min = -.4, max = .4, value = .4, step = .025),
sliderInput("b2", label = withMathJax("\\(\\beta_2\\)"), min = -.4, max = .4, value = .4, step = .025),
sliderInput("b3", label = withMathJax("\\(\\beta_3\\)"), min = -.2, max = .2, value = .2, step = .025)
)
r <- reactive({
set.seed(12479)
nobs <- 200
x <- rnorm(nobs)
z <- rnorm(nobs)
r2 <- input$b1^2 + input$b2^2 + input$b3^2
y <- input$b1 * x + input$b2 * z + input$b3 * x*z + rnorm(nobs, sd = sqrt(1 - r2))
d <- data.frame(x, z, y)
fit_int <- lm(y ~ x*z, data = d)
fit_noint <- lm(y ~ x+z, data = d)
scale <- seq(-3, 3, length.out = 30)
dp <- expand.grid(x = scale, z = scale, KEEP.OUT.ATTRS = FALSE)
dp_int <- dp %>%
mutate(., y = predict(fit_int, .)) %>%
filter(-3 <= y, y <= 3)
dp_noint <- dp %>%
mutate(., y = predict(fit_noint, .)) %>%
filter(-3 <= y, y <= 3)
return(list(
d = d,
fit_int = fit_int,
fit_noint = fit_noint,
dp_int = dp_int,
dp_noint = dp_noint))
})
renderRglwidget({
try(rgl.close())
layout3d(matrix(c(1,1,2,3), byrow = TRUE, ncol = 2), sharedMouse = TRUE)
with(r()$d, plot3d(x, z, y, xlim = c(-3, 3), ylim = c(-3, 3), zlim = c(-3, 3), main = "scatter"))
next3d()
with(r()$d, plot3d(x, z, y, xlim = c(-3, 3), ylim = c(-3, 3), zlim = c(-3, 3), main = "with int"))
with(r()$dp_int, points3d(
x, z, y, col = rgb(1,0,0), alpha = .25))
next3d()
with(r()$d, plot3d(x, z, y, xlim = c(-3, 3), ylim = c(-3, 3), zlim = c(-3, 3), main = "without int"))
with(r()$dp_noint, points3d(
x, z, y, col = rgb(0,.5,0), alpha = .25))
rglwidget(width = 1400)
})
```
答案 0 :(得分:1)
将此功能添加到您的代码中:
myRenderRglwidget <- 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)
}
然后拨打renderRglwidget
,然后拨打myRenderRglwidget
,而不是拨打outputArgs = list(width = 1400)
最后添加一个额外的参数 with(r()$dp_noint, points3d(
x, z, y, col = rgb(0,.5,0), alpha = .25))
rglwidget()
}, outputArgs = list(width = 1400))
,即
你的代码块的最后几行应该是
rgl
此修改最终会进入myRenderRglwidget
,您不需要使用renderRglwidget
,您只需使用private func setTheDictionary() {
for floor in storedFloors {
floorsAndRooms["\(floor.floorNumber)"] = "\(floor.numberOfRooms)"
}
}
即可参数。