Search code examples
rr-markdownplotlyhugoblogdown

How to make plotly charts adjust to page width using rmarkdown?


I have an R blog post with some leaflet and plotly figures. I can set width = "100%" in the leaflet() function, and the leaflet map will change shape as I resize my browser window (or view on mobile). I've tried the same width = "100%" in plot_ly(), but the plot doesn't resize for smaller windows and requires horizontal scrolling.

Any ideas? I'm using blogdown/hugo if that is helpful.


Solution

  • Use the chunk option:

    ```{r, out.width='100%'}