6

rmarkdown 的默认选项是设置 fig.width = 12。如果可能的话,我希望它能够自动调整移动设备的宽度。

我在http://akdata.org/misc/leafletmobile托管以下 Rmarkdown

---
title: "Untitled"
output: html_document

---


```{r}      
  library(leaflet)
  leaflet() %>% addTiles()
``

当我在 chrome devtools 中使用不同的移动设备时,它会调整到屏幕的宽度。我有一个正在测试的实体三星 Galaxy 5。

4

2 回答 2

7

我认为指定一个百分比width会给你你想要的结果。下面是你将如何做到这一点rmarkdown,这里是一个活生生的例子。不幸的是,如果你还指定一个百分比height,你的屏幕会因为某处的一些错误而显示为空白,所以它不是完全响应的,但它仍然可以在我的 iPhone 上很好地调整。

---
title: "responsive_leaflet"
author: "TimelyPortfolio"
date: "March 24, 2016"
output:
  html_document:
   mathjax: null
---

```{r echo=FALSE, warning=FALSE}
# no help from a framework
#  just percentage height and width
library(leaflet)

l <- leaflet(width="100%") %>%
  addTiles()
l
```

```{r echo=FALSE, warning=FALSE}
# demonstrate with Bootstrap
library(shiny)

fluidRow(
  column(width=10,l)
)
```
于 2016-03-24T21:39:23.117 回答
2
<div id="htmlwidget-4092" style="width:75%; height:75%; position:absolute" class="leaflet html-widget"></div>

此代码块出现在源代码底部附近。尺寸可以按百分比制作,它会自动调整大小以适应屏幕。任何百分比都应该有效。此外,position: absolute还需要确保它保持在正确的位置。

注意:我建议找到一种方法来缩短页面源中的那些大量链接。

于 2016-03-22T01:28:12.003 回答