简体   繁体   中英

Get plotly in an Rmarkdown file to occupy all horizontal space in HTML

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:

在此处输入图像描述

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?

```{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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM