rmarkdown icon indicating copy to clipboard operation
rmarkdown copied to clipboard

Set shiny plot size based on rmarkdown figure size

Open jiho opened this issue 8 years ago • 1 comments

Currently, in a dynamical rmarkdown document, the plot size from shiny is independent from the fig.width and fig.height or rmarkdown, leading to heterogeneous output. One has to match width and height (and the resolution see rstudio/shiny#1832) to get homogeneously sized output. It would be nicer if "auto" (which gets the offsetWidth/offsetHeight of the corresponding HTML element) could fetch those from the chunk options (i.e. if the chunk options would affect the offsetWidth and offsetHeight of the corresponding HTML element).

---
title: "rmd image size"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.retina=1)
library("ggplot2")
library("shiny")
```

```{r fig.width=5, fig.height=2}
ggplot(mtcars) + geom_point(aes(wt, mpg))
```

```{r fig.width=5, fig.height=2}
renderPlot({
  ggplot(mtcars) + geom_point(aes(wt, mpg))
})
```

```{r}
renderPlot({
  ggplot(mtcars) + geom_point(aes(wt, mpg))
}, width=5*96, height=2*96, res=96)
```

jiho avatar Aug 29 '17 08:08 jiho

NB: cross-posting from https://github.com/rstudio/shiny/issues/1833 since I don't really know whether this is a shiny or rmarkdown problem. Possibly both.

jiho avatar Aug 29 '17 08:08 jiho