1

I'm trying to use plotly in an Rmarkdown file, but the plots all get rendered in HTML without occupying the available horizontal space and therefore feel very cramped. I've tried the solution found here (out.width='100%'), but to no effect:

---
title: "R Notebook"
output: html_notebook
---

[filler text]

```{r, out.width='100%'}
suppressPackageStartupMessages(library(plotly))

plotly::plot_ly() %>%
  add_lines(
    x = seq(1:1000),
    y = runif(1000)
  ) %>%
  layout(
    autosize = TRUE
  )
```

This gets rendered in HTML (on Chrome) as:

enter image description here

I've also tried calling knitr::opts_chunk$set(out.width = "100%") directly (in its own chunk before the plot), but to no effect.

Following @Axeman's comment, I also tried setting output: html_document. This works as far as getting plotly to fill the horizontal space, but disables table pagination. So my actual use-case, which includes tables with hundreds of lines, becomes unusable, demanding endless scrolling past those tables.

How should this be done?

Wasabi
  • 2,879
  • 3
  • 26
  • 48
  • 2
    This seems to be linked to using `html_notebook`, if I use `html_document` as output it works as expected for me. – Axeman Jun 05 '20 at 20:06
  • @Axeman indeed, that works for me, too. But my actual case also includes tables with hundreds of lines, and using `html_document` seems to disable the table pagination, so the document basically becomes 99% tables and 1% other content. – Wasabi Jun 05 '20 at 20:34

1 Answers1

0
```{r set-options, echo=FALSE, cache=FALSE}
options(width = 10000)
```

only made it as wide as the margins that displays the code chunk, but like mentioned in the comments, only seemed to work when knitted to html_document.

Daniel_j_iii
  • 3,041
  • 2
  • 11
  • 27