R: flexdashboard shrinks content, any way to prevent this?

5.2k views Asked by At

I ran R markdown with 8 stocks and with 12 stocks. As you can see the stock charts get increasingly smaller. Is there any way to force flexdashboard to keep a larger width? I don't mind vertically scrolling when there are 12 or more stocks on a screen.

rmarkdown::render('foo.Rmd')
# creates foo.html

enter image description here

foo.Rmd

---
title: "Semiconductor: 5 years"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
---

```{r setup, include=FALSE}
library(quantmod)
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)
getSymbols(c("APH","IBM","CCL","TSS","HSY","COH","QRVO","CMA","RJF","ABBV","SCHW","RTN"), src="yahoo", from="2012-01-01")
```

Row
-------------------------------------
### APH
```{r, fig.height=5}
chartSeries(APH, type="line", subset="last 5 years", TA=NULL)
```

### IBM
```{r, fig.height=5}
chartSeries(IBM, type="line", subset="last 5 years", TA=NULL)
```

### CCL
```{r, fig.height=5}
chartSeries(CCL, type="line", subset="last 5 years", TA=NULL)
```

### TSS
```{r, fig.height=5}
chartSeries(TSS, type="line", subset="last 5 years", TA=NULL)
```



Row
-------------------------------------
### HSY
```{r, fig.height=5}
chartSeries(HSY, type="line", subset="last 5 years", TA=NULL)
```

### COH
```{r, fig.height=5}
chartSeries(COH, type="line", subset="last 5 years", TA=NULL)
```

### QRVO
```{r, fig.height=5}
chartSeries(QRVO, type="line", subset="last 5 years", TA=NULL)
```

### CMA
```{r, fig.height=5}
chartSeries(CMA, type="line", subset="last 5 years", TA=NULL)
```



Row
-------------------------------------
### RJF
```{r, fig.height=5}
chartSeries(RJF, type="line", subset="last 5 years", TA=NULL)
```

### ABBV
```{r, fig.height=5}
chartSeries(ABBV, type="line", subset="last 5 years", TA=NULL)
```

### SCHW
```{r, fig.height=5}
chartSeries(SCHW, type="line", subset="last 5 years", TA=NULL)
```

### RTN
```{r, fig.height=5}
chartSeries(RTN, type="line", subset="last 5 years", TA=NULL)
```

foo.Rmd (with vertical scroll)

---
title: "Semiconductor: 5 years"
output:
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    orientation: rows
---

```{r setup, include=FALSE}
library(quantmod)
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)
getSymbols(c("MTB","IVZ","UAL","MOS","MCK","ADSK","LEG","STT","RMD","EBAY","RF","FIS"), src="yahoo", from="2012-01-01")
```

Row
-------------------------------------
### MTB
```{r}
chartSeries(MTB, type="line", subset="last 5 years", TA=NULL)
```

### IVZ
```{r}
chartSeries(IVZ, type="line", subset="last 5 years", TA=NULL)
```

### UAL
```{r}
chartSeries(UAL, type="line", subset="last 5 years", TA=NULL)
```

### MOS
```{r}
chartSeries(MOS, type="line", subset="last 5 years", TA=NULL)
```



Row
-------------------------------------
### MCK
```{r}
chartSeries(MCK, type="line", subset="last 5 years", TA=NULL)
```

### ADSK
```{r}
chartSeries(ADSK, type="line", subset="last 5 years", TA=NULL)
```

### LEG
```{r}
chartSeries(LEG, type="line", subset="last 5 years", TA=NULL)
```

### STT
```{r}
chartSeries(STT, type="line", subset="last 5 years", TA=NULL)
```



Row
-------------------------------------
### RMD
```{r}
chartSeries(RMD, type="line", subset="last 5 years", TA=NULL)
```

### EBAY
```{r}
chartSeries(EBAY, type="line", subset="last 5 years", TA=NULL)
```

### RF
```{r}
chartSeries(RF, type="line", subset="last 5 years", TA=NULL)
```

### FIS
```{r}
chartSeries(FIS, type="line", subset="last 5 years", TA=NULL)
```
2

There are 2 answers

4
Kevin Arseneau On

Add vertical_layout: scroll to your YAML

---
title: "Semiconductor: 5 years"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
---

Getting the plot to fill each box in a way to meet your tastes using this method requires experimentation, according to the package site.

We’ve specified an explicit fig.height and fig.width for each chart so that their rendered size fits their flex container as closely as possible. Note that the ideal values for these dimensions typically need to be determined by experimentation.

To improve the viewing of the plots, you may prefer to switch to tabs

---
title: "Semiconductor: 5 years"
output:
  flexdashboard::flex_dashboard:
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(quantmod)
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)
getSymbols(c("APH","IBM","CCL","TSS","HSY","COH","QRVO","CMA","RJF","ABBV","SCHW","RTN"), src="yahoo", from="2012-01-01")
```

Column {.tabset}
-------------------------------------
### APH
```{r}
chartSeries(APH, type="line", subset="last 5 years", TA=NULL)
```

### IBM
```{r}
chartSeries(IBM, type="line", subset="last 5 years", TA=NULL)
```

### CCL
```{r}
chartSeries(CCL, type="line", subset="last 5 years", TA=NULL)
```
1
AG1 On

A combination of Row {data-height=200) and {r, fig.height=3, fig.width=5} and vertical_layout: scroll has solved the issue for me.

semi.Rmd ... R -e "rmarkdown::render('semi.Rmd')"

---
title: "Semiconductor: 5 years"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
---

```{r setup, include=FALSE}
library(quantmod)
# 4 stocks
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)
getSymbols(c("INTC","TXN", "QCOM","NVDA","AVGO","STM","AMD","CY","TSM","ADI"), src="yahoo", from="2012-01-01")
```

Row {data-height=200}
-------------------------------------
### Intel
```{r, fig.height=3, fig.width=5}
chartSeries(INTC, type="line", subset="last 5 years", TA=NULL)
```

### Qualcomm
```{r, fig.height=3, fig.width=5}
chartSeries(QCOM, type="line", subset="last 5 years", TA=NULL)
```

### Texas Instruments
```{r, fig.height=3, fig.width=5}
chartSeries(TXN, type="line", subset="last 5 years", TA=NULL)
```

### Broadcom
```{r, fig.height=3, fig.width=5}
chartSeries(AVGO, type="line", subset="last 5 years", TA=NULL)
```

Row {data-height=200}
-------------------------------------
### ST Microelectronics
```{r, fig.height=3, fig.width=5}
chartSeries(STM, type="line", subset="last 5 years", TA=NULL)
```

### AMD
```{r, fig.height=3, fig.width=5}
chartSeries(AMD, type="line", subset="last 5 years", TA=NULL)
```

### Cypress
```{r, fig.height=3, fig.width=5}
chartSeries(CY, type="line", subset="last 5 years", TA=NULL)
```

### NVDA
```{r, fig.height=3, fig.width=5}
chartSeries(NVDA, type="line", subset="last 5 years", TA=NULL)
```

Row {data-height=200}
-------------------------------------
### TSMC
```{r, fig.height=3, fig.width=5}
chartSeries(TSM, type="line", subset="last 5 years", TA=NULL)
```

### Analog Devices
```{r, fig.height=3, fig.width=5}
chartSeries(ADI, type="line", subset="last 5 years", TA=NULL)
```